<h2>//Call ajax function on autocomplete in jquery</h2>
$(document).ready(function(){
jQuery("#name").autocomplete({
source: function(request, response) {
$.ajax({
url: 'include/get.php',
type: "POST",
data: {
term : request.term,
data :$("#form1").serializeArray()
},
success: function(data) {
data=JSON.parse(data);
response(data);
} <br>
});
},
minlength:1
});
});
Here onclick of name it calls ajax file get.php where it sends the form data and the entered term .
The response we get which is in json format is again parsed as
data=JSON.parse(data);
to get the result otherwise it shows jquery error. Means the data is parsed as json twice to display the result in correctly.
0 Comment(s)