I'm using the modernish jquery 1.5 ajax request. To a page on the same domain. I'm trying to improve upon behaviour in an intranet site using grease monkey and jquery.
var jqxhr = $.ajax("anotherpage-response.html")
.success(function(data) {alert("cmp"); console.log(data);})
.error(function() { alert("error"); })
.complete(function() { alert("complete"); });
Its currently being returned as a string. Any idea how I can get it returned as a dom like object which I can proccess using jquery selectors ???
I think im after something like fileType: html
but it doesnt seem to be an option in the ajax request. Maybe I just need to read the api properly ???
Thanks
You should read up on jquery's documentation on this subject: http://api.jquery.com/jQuery.ajax/ The thing you are looking for probably is the following: dataType.
$.ajax({
url: 'request.html',
succes: function(data){
.. do something here! ..
},
dataType: 'html'
});
I hope this helps
No matter what you will get back a string as plain text.
From the jQuery docs on dataType:
""html": Returns HTML as plain text; included script tags are evaluated when inserted in the DOM."
You can always turn plaintext into a dom object though..
$.ajax({
url: 'request.html',
succes: function(data){
$(data) // This is now (kind of) a DOM object that you can use jQuery selectors on
},
dataType: 'html'
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With