我正在尝试将文件上传到PHP我的server.file和数据上传通过多部分/表格数据,在PHP服务器上收到的文件和数据但在我的PHP服务器上返回json响应.请帮助我如何在我的网页中读取json响应如果它的成功(代码= 0)意味着它重定向另一个页面.phroid服务器对于android和网页都是常见的.json响应看起来像{“code”:0,“message”:“success”}
最佳答案
我认为它应该适合你.像我一样使用AJAX
//Your PHP code
$arrToJSON = array(
"dataPHPtoJs"=>"yourData","asYouWant"=>"PHP evaluate
var dt={
ObjEvn:"btn_Login",dataJsToPHP: $("#txt_EmailLogin").val()
};
//Ajax
var request =$.ajax({//http://api.jquery.com/jQuery.ajax/
url: "yourServer.PHP",type: "POST",data: dt,dataType: "json"
});
//Ajax Done catch JSON from PHP
request.done(function(dataset){
for (var index in dataset){
dataPHPtoJsJS=dataset[index].dataPHPtoJs;
asManyasYouWantJS=dataset[index].asYouWant;
}
//JavaScript conditions. Here you can control the behaivior of your html object,based on your PHP response
if(dataPHPtoJsJS){
$( "#idYourHtmlElement" ).removeClass( "class1" )
$( "#idYourHtmlElement" ).addClass( "class2" )
}
});
//Ajax Fail
request.fail(function(jqXHR,textStatus) {
alert("Request Failed: " + textStatus);
});
}
原文地址:https://www.jb51.cc/html/426528.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。