Solved

Jquery autocomplete return data to a script

Posted on 2014-04-14
5
317 Views
Last Modified: 2014-05-15
Hi,
I'm using jquery and autocomplete to query a database of names and return a given name/id.
With the help of EE, I have gotten this to work properly.
I'm at the next stage now, where i need to take the ID I returned, I pass it to a server side script, in this case a perl script.
Can someone show me how I go about doing this in jquery.
Here is the current jquery code I'm using to get the names and return the employeeid to an alert box.
How can i return the employee to a server side script?

<script>

$(document).ready(function(){

$(function() {

$( "#tags" ).autocomplete({
source: "../f/getnames2.pl",
minLength: 2,
select: function(event,ui){
var employeeid = ui.item.empid;

$("#getemp").click(function(employee){
alert(employeeid);
});

}


});


});

});
</script>

Open in new window





Thanks!
Nacht
0
Comment
Question by:nachtmsk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 39999241
Where you have

$("#getemp").click(function(employee){
alert(employeeid);
});

Open in new window


You will instead to an ajax post
$("#getemp").click(function(employee){
// EmployeeID is the field name you are passing
// employeeid is the data being returned from the callback
// you can also make this a separate function.
$.ajax({
  type: "POST",
  url: "some.php",
  data: { EmployeeID: employeeid}
})
  .done(function( msg ) {
    alert( "Data Saved: " + msg );
  });

});

Open in new window

0
 
LVL 53

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 39999248
I forgot to mention, the example I used is directly from https://api.jquery.com/jQuery.ajax/

Instead of posting to a php page, it would be your script.
0
 

Author Comment

by:nachtmsk
ID: 39999259
Hi Scott,

Thanks.
I found a similar example online and tried it. I was able to get the alert to show that the POST was successful. I also put the data into an alert and saw the source code of the HTML/data I was returning from the script.
however, how do I return the page to display in the browser and not just in an alert window?
0
 

Author Comment

by:nachtmsk
ID: 39999271
I have this, which works, but only display the response in an alert window.. not a browser.

<script>

$(document).ready(function(){

$(function() {

$( "#tags" ).autocomplete({
source: "../f/getnames2.pl",
minLength: 2,
      select: function(event,ui){
      var employeeid = ui.item.empid;
      
      $("#getemp").click(function(){
      //alert(employeeid);
      $.post("http://www.test.com/f/test.pl",
            {
            
             username:"jsmith",
             guid:"AJJD88AD2-27CC-4D06-B1E7-18EAA80C2957"
            },
            function(data,status){
            alert(status);
            alert(data);
            });
      
            
            
      });
      
      }

      
      });


      });
      
});
</script>
0
 
LVL 2

Expert Comment

by:vogen
ID: 40050551
you need to add html element and set the value
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question