Parse XML with jquery ajax and xpath
I stuck with following constellation:
JSBIN Example
I want a click function for Check Availibility that does a jquery ajax with a given url (i.e. http://kiris-alinda.de/temp/verify.php) checks if the attribute @ges has a value (ie ges="1234") or not (ie ges="") and finally alerts "true" or "false"
XML Response with true: http://kiris-开发者_JS百科alinda.de/temp/verify_true.php XML Response with false: http://kiris-alinda.de/temp/verify_false.php
Thanks a lot in advance for your feedback and an interesting discussion...
you can try this approach
$.ajax({
url: 'http://kiris-alinda.de/temp/verify.php',
type: 'GET',
datatype: 'xml',
success: function(responseValue) {
var gesVal = $(responseValue).find('ges').text();
if(gesVal !=null && gesVal !=undefined && gesVal != ""){
alert("true");
}else{
alert("false");
}
},
error: function(jqXHR, textStatus, errorThrown) {
//error handling goes here
}
});
To perform the AJAX call the jQuery is as follows
$.ajax({
url: 'http://kiris-alinda.de/temp/verify.php',
type: 'GET',
datatype: 'xml',
success: function(data, textStatus, jqXHR) {
//xml returned in 'data' - interrogate for response here
},
error: function(jqXHR, textStatus, errorThrown) {
//error handling goes here
}
});
精彩评论