Trying to find div
element with id=\"result\"
in returned data from .ajax()
using .find()
. Unfortunately, alert(res
You might have to do something like
var content= (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d
then you should be able to use
result = $(content).find("#result")
This worked for me, you just need to put .html() on the end of - $(response).find("#result")
The jQuery find() is returning a jQuery object that wraps the DOM object. You should be able to work with that object to do what you'd like with the div.
Specify dataType: "html"
.
If you do not jQuery will guess the requested data type (check: http://api.jquery.com/jQuery.ajax/). My guess is that in your case response
was a String
rather than a DOMObject
. Obviously DOM methods won't work on a String.
You could test that with console.log("type of response: " + typeof response)
(or alert("type of response:" + typeof response)
, in case you don't run Firebug)
try if( $(response).filter('#result').length ) // do something
$.ajax({
url: url,
cache: false,
success: function(response) {
$('.element').html(response);
}
});
< span class = "element" >
//response
< div id = "result" >
Not found
</div>
</span>
var result = $("#result:contains('Not found')").text();
console.log(result); // output: Not found