PHP AJAX response in XML string -


i have web page making ajax call echoes xml string in below format:

<ecg>abnormal</ecg><sp>10.99</sp><bp>120/90</bp><oxy>139</oxy><tmp>23</tmp> 

ajax call

$.ajax({         type:'post',         url: 'check_status.php',         datatype: 'xml',         success: function(xml) {                         var ecg = $(xml).find("ecg").text();                          var sp = $(xml).find("sp").text();                          var bp = $(xml).find("bp").text();                          var oxy = $(xml).find("oxy").text();                          var tmp = $(xml).find("tmp").text();                          alert(tmp);         },         error: function(){                         alert('error');                         update();         }         }); 

the xml response created php backend script constructing xml string:

$resp = "<ecg>" . $ecg . "</ecg>" .... echo $resp; 

but still alert in ajax error method called - there else need backend script.

as told in comments, response isn't formed xml. you're missing document node wraps other nodes. this:

<?xml version="1.0"?> <response>   <ecg>abnormal</ecg>   <sp>10.99</sp>   <bp>120/90</bp>   <oxy>139</oxy>   <tmp>23</tmp> </response> 

also encouraged set proper content type header php:

header('content-type: text/xml'); 

(before output)


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -