I have asp.net mvc web api 2 url. I need to use that web API data integrate to PHP application search and data(postcode display list) auto complete. These below my jQuery and PHP search page code, but it is not working for me. Please tell me why was that?
This is asp.net mvc web api 2 JSON return values.
[{"ID":6,"SuburbName":"Carlton North","postcode":"3054","Territory":"MEL-Brunswick","Latitude":- 37.7845911,"Longitude":144.972883,"AuState":"VIC","created":"13/03/2015 12:00:00 AM","updated":"13/03/2015 12:00:00 AM"}
[{"ID":7,"SuburbName":"Carlton South","postcode":"3054","Territory":"MEL-Brunswick","Latitude":- 37.7845911,"Longitude":144.972883,"AuState":"VIC","created":"13/03/2015 12:00:00 AM","updated":"13/03/2015 12:00:00 AM"}
This is my jQuery code
var searchRequest = null;
$(".auto").autocomplete({
maxLength: 5,
source: function(request, response) {
if (searchRequest !== null) {
searchRequest.abort();
}
searchRequest = $.ajax({
url: 'asp.net mvc api web url',
method: 'post',
dataType: "json",
data: {term: request.term},
success: function(data) {
searchRequest = null;
response($.map(data.items, function(item) {
return {
value: item.SuburbName,
label: item.SuburbName
};
}));
}
}).fail(function() {
searchRequest = null;
});
}
});
<form method="POST" action="search.php">
Enter your Postcode:
<input type="text" name="search" >
<input name="submit" type="submit" class="auto" value="<?php echo $_POST['search'];?>" /><br />
</form>
if(isset($_POST['submit']))
{
$value=$_POST['search'];
}
" + item.SuburbName + "" ) .appendTo( ul ); };`
" + item.SuburbName + "" ) .appendTo( ul ); };autocomplete( "instance" )._renderItem = function( ul, item ) { return $( "
" + item.SuburbName + "" ) .appendTo( ul ); };