开发者

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
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜