Reputation: 754
I have mockjax for auto complete and it is working great.I have no issue with mockjax and do not want to change it.
Here is its code
$.mockjax({
url: '*',
responseTime: 2000,
response: function (settings) {
var query = settings.data.query,
queryLowerCase = query.toLowerCase(),
re = new RegExp('\\b' + $.Autocomplete.utils.escapeRegExChars(queryLowerCase), 'gi'),
suggestions = $.grep(countriesArray, function (country) {
// return country.value.toLowerCase().indexOf(queryLowerCase) === 0;
return re.test(country.value);
}),
response = {
query: query,
suggestions: suggestions
};
this.responseText = JSON.stringify(response);
}
});
Now on the same page i have to use jquery post which give me error
$.post("save.php", { id:id }, function(data) {
alert(data);
});
It qive me error "query not define"
Please teach me how to use both on one page with out disturbing other?
Upvotes: 0
Views: 1610
Reputation: 189
The object you are passing to jQuery.post
does not have a query
key, but you are trying to reference it in the first line of the mockjax response function: settings.data.query
Mockjax just passes whatever data you try to post with jQuery to the callback you specify.
See how this feature works in a simple example: http://jsfiddle.net/gabor_nagy/N4x2Z/
Upvotes: 1