由网友(个性女生霸气高傲)分享简介:我的问题是,我想从服务器上的XML文件返回给客户端,并使用jquery的AJAX功能解析它。这是code:My problem is that I want to return an xml file from server back to client and parsing it using ajax funct...
我的问题是,我想从服务器上的XML文件返回给客户端,并使用jquery的AJAX功能解析它。这是code:
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:
客户端:
$("#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);
}
});
});
服务器(php文件),
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??
好吧,我发现它。我的php文件在这种形式
ok I found it. my php file was in this form
//some code
include("other.php");
//some other code
其中other.php文件是我上面张贴的文件。我剪切/粘贴的标头,这样最终的PHP文件将是
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
和other.php
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!
推荐答案
这是工作的罚款
post.php中文件
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);
}
});
}
相关推荐
最新文章