My problem is that I want to return an xml file from server back to client and parsing it using ajax function of jquery. This is the code:
Client:
$("#submit").click(function(){
$.ajax({
type: "POST",
url: "search.php",
data: "whatever",
dataType: "xml",
async: false,
success: function(xml){
var data = $('doctor',xml).text();
alert(data);
}
});
});
Server(php file),
header('Content-type: text/xml');
echo '<?xml version="1.0" encoding="utf-8"?>';
echo "<tables>";
echo "<doctor>Someone</doctor>";
echo "</tables>";
I have a blank alert and I do not know why??
//some code
include("other.php");
//some other code
where the other.php file was the file I posted above. I cut/paste the header so the final php file would be
//some code
header('Content-type: text/xml');
include("other.php");
//some other code
and other.php
echo '<?xml version="1.0" encoding="utf-8"?>';
echo "<tables>";
echo "<doctor>Someone</doctor>";
echo "</tables>";
now it works perfect. Thanks for your quick replies!
This is working fine
Post.php file
if($_GET['id']!=""){
$array = array('satyam' => 'satyam',
'class' => 'B.TECH',
'company' => 'Ranosys');
}
$new ='<?xml version="1.0" encoding="iso-8859-1"?><data>';
foreach($array as $key => $values){
$new .= "<$key>$values</$key>";
}
echo $new.'</data>';
=================
function load_data(){
$.ajax({
url: "post.php",
async: false, // stop browser for another activity
data: "id=satyam",
// dataType :'xml',
error: function(e, b, error) {
for(var i in e){
// alert(i);
}
alert(e.respone);
},
success: function(msg) {
//alert($response);
var data = $(msg).find("satyam").text();
alert(data);
}
});
}
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