jQuery search string in string in comb. with AJAX
Hello again stackoverflow!
So i have this file, called serverche开发者_C百科ck.php
. I want to use ajax to load the contents. If the contents contains an 1
, i want to return true, else, return false.
So i already have this:
$.get('servercheck.php', function(data) {
// Now i wanna search the string data for an 1
});
I already searched through :contains
and .find()
but that is both for HTML tags...
Maybe use javascript indexOf:
$.get('servercheck.php', function(data) {
if(data.indexOf("1") != -1) {
return true;
}
return false;
});
I think jQuery deferred objects can help you here. The best place to start will be here
http://api.jquery.com/jQuery.when/
Hope this helps!
you are supposed to send the data to search for firstly then the coming data is the result of search and specify the data format for returned data from server i use json
$.get("servercheck.php",{key:'data-to-search-for'},function(data){
alert(data.count);
alert(data.results[1]);
},'json');
this is depending on how you render the json with php count , array of result add variables as you can
i always use post instead of get!!! don't know why but i prefer it
精彩评论