ajax无法检索PHP解析的数组

ajax无法检索PHP解析的数组,php,html,jquery,mysqli,Php,Html,Jquery,Mysqli,我在弹出窗口中设置了一个表格,显示特定用户ID下的订单 <div id="shpcart"> <div id="shpop"> <table> <thead> <tr><th></th><th>Item name</th><th colspan="2">Price</th><th>shipping</th></tr><

我在弹出窗口中设置了一个表格,显示特定用户ID下的订单

<div id="shpcart">
<div id="shpop">
<table>
<thead>
   <tr><th></th><th>Item name</th><th colspan="2">Price</th><th>shipping</th></tr><th>Quantity</th>
</thead>
<tbody id= "cartbody">

</tbody>
</table>
</div>
</div>

项目名称价格发货数量
下面是将用户ID发送到服务器的ajax

$(function(){            

    $(".prod_buy").click(function(){

    var htmlId = $(this).attr('id');
    var idarray = htmlId.split('-');
    var itemId = idarray[1];
    $.ajax({
 type: "POST",
 url: "tempselector.php",
 data: {'proId': itemId  }
 }).done(function( msg ) {
 jQuery.parseJSON(msg);
 var output = jQuery.parseJSON(msg);
 var htmlstring;
 alert ("im running");
 for(var index=0;index<output.length; index++){
  var itmnam = output[index][1];
  var itmpic = output[index][2];
  var itmpr = output[index][3];
  var itmdisc = output[index][4];
  var itmdesc = output[index][5];
  var itmshp = output[index][6];
  var itmav = output[index][7];

  htmlstring +="<tr><th><img src = '../cartimg/'"+itmpic+"></th><td>"+itmnam+"</td><td>"+itmdisc+"</td><td>"+itmshp+"</td><td>QTY</td></tr>";


  }
  $('#cartbody').html(htmlstring);

  $("#shpcart").fadeIn();
  });


  });
$(函数(){
$(“.prod_buy”)。单击(函数(){
var htmlId=$(this.attr('id');
var idarray=htmlId.split('-');
var itemId=idarray[1];
$.ajax({
类型:“POST”,
url:“tempselector.php”,
数据:{'proId':itemId}
}).done(函数(msg){
json(msg);
var output=jQuery.parseJSON(msg);
var-htmlstring;
警报(“我正在运行”);

关于ajax方法(var index=0;index),您可以尝试以下代码:

$.ajax({
  url:'tempselector.php',
  dataType:"json",
  type:"GET",
  data: {'proId': itemId  },
  error: function(XMLHttpRequest, textStatus, errorThrown) {
        $('body').append(XMLHttpRequest.responseText);
  },
  success:function(output){
        var htmlstring;
        for(var index=0;index<output.length; index++){
            var itmnam = output[index][1];
            var itmpic = output[index][2];
            var itmpr = output[index][3];
            var itmdisc = output[index][4];
            var itmdesc = output[index][5];
            var itmshp = output[index][6];
            var itmav = output[index][7];
            htmlstring +="<tr><th><img src = '../cartimg/'"+itmpic+"></th><td>"+itmnam+"</td><td>"+itmdisc+"</td><td>"+itmshp+"</td><td>QTY</td></tr>";
        }
        $('#cartbody').html(htmlstring);
        $("#shpcart").fadeIn();
  }
});
$.ajax({
url:'tempselector.php',
数据类型:“json”,
键入:“获取”,
数据:{'proId':itemId},
错误:函数(XMLHttpRequest、textStatus、errorshown){
$('body').append(XMLHttpRequest.responseText);
},
成功:功能(输出){
var-htmlstring;

对于(var index=0;index如果存在不必要的输出,则无法解析json,这就是问题所在。问题已经解决了

我无法帮助您解决问题,但我确实发现您的问题标题具有误导性。您是否存在数据问题,或者弹出窗口不工作?我已经修改了标题,现在应该已经足够清楚了:)我相信你会得到更好的回应。我可能对AJAX和JSON了解不多,有些是的,但我知道得很多:
$uId
,我在其他任何地方都看不到它(只有一次),它是如何被引用的?同样
$link
,只显示一次。它们是否设置在您的
tempselector.php
文件中?是的,它们在这里:session_start();include('includes/config.php');$uId=$\u session[“uId”];我能够回显json_encode($array);字段已成功完成
$.ajax({
  url:'tempselector.php',
  dataType:"json",
  type:"GET",
  data: {'proId': itemId  },
  error: function(XMLHttpRequest, textStatus, errorThrown) {
        $('body').append(XMLHttpRequest.responseText);
  },
  success:function(output){
        var htmlstring;
        for(var index=0;index<output.length; index++){
            var itmnam = output[index][1];
            var itmpic = output[index][2];
            var itmpr = output[index][3];
            var itmdisc = output[index][4];
            var itmdesc = output[index][5];
            var itmshp = output[index][6];
            var itmav = output[index][7];
            htmlstring +="<tr><th><img src = '../cartimg/'"+itmpic+"></th><td>"+itmnam+"</td><td>"+itmdisc+"</td><td>"+itmshp+"</td><td>QTY</td></tr>";
        }
        $('#cartbody').html(htmlstring);
        $("#shpcart").fadeIn();
  }
});