Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JSON返回到PHP代码末尾,而不是mobile.html_Javascript_Php_Json - Fatal编程技术网

Javascript JSON返回到PHP代码末尾,而不是mobile.html

Javascript JSON返回到PHP代码末尾,而不是mobile.html,javascript,php,json,Javascript,Php,Json,我的PHP文件可用于web和移动设备。Javascript文件将ajax/json定向到mobile.html。当使用mobile.html时,JSON返回到PHP代码的末尾,在html代码开始之前。 我粘贴了代码。我是一名学生,如果我的帖子令人困惑,请允许我提前道歉 函数getProductPerdomo(){ var cigarName=“”; var price=“” var supplyAmount=“”; $.ajax({ url:'selectperdomo.php', 键入:“P

我的PHP文件可用于web和移动设备。Javascript文件将ajax/json定向到mobile.html。当使用mobile.html时,JSON返回到PHP代码的末尾,在html代码开始之前。 我粘贴了代码。我是一名学生,如果我的帖子令人困惑,请允许我提前道歉

函数getProductPerdomo(){
var cigarName=“”;
var price=“”
var supplyAmount=“”;
$.ajax({
url:'selectperdomo.php',
键入:“POST”,
数据类型:“JSON”,
数据:{
手机:“是的”
},
成功:函数(json){
$.each(json,函数(键,值){
cigarName=value.cigar\u name;
price=“price:”+value.price;
supplyAmount=“库存:”+value.supply;
});
$('#perdomonamehere').html(cigarName);
$('perdomopricehere').html(价格);
$('#perdomospplyhere').html(supplyAmount);
}
})
}


产品

一盒24

数量:
您的图像链接已断开。您希望从selectperdomo.php文件中得到什么?JSON还是HTML?您正在输出(或似乎试图输出)两者,但ajax调用只允许您接收返回的1或另一个。您的ajax调用表明您希望返回JSON(
dataType:“JSON”
),感谢Patrick Q。图中显示了chrome developer工具网络——JSON在HTML代码开始之前返回到PHP代码的末尾。JSON数据应该已经转到我上面粘贴的HTML中了。Josh KG-我期待JSON回来。JSON发送雪茄的名称、价格和供应。这些数据应该发布到上面html中的id=“perdomonamehere”等中。但是,在PHP文件中,有用于web页面的HTML。这就像客户机被搞糊涂了,不知道把它放在哪里,所以它在html文件中作为json编码的数据扑通一声。感谢所有帮助过它的人。我将结束括号移到HTML的末尾,JSON返回到正确的位置。关闭