dongma6326 2013-08-27 20:33
浏览 686
已采纳

非常简单的ajax请求返回[object Object]

Here is the javascript part of the code;

$.ajax
({
  type: 'POST',
  url: location.href,
  data: {
  'uploaded_data' : 'uploaded_data',
  },
  dataType: 'text',
  success: function(message) {},
  complete: function(message) 
  {
     alert(message);
  }
});

And here is the php part;

if(isset($_POST["uploaded_data"]))
{
    $text="test text";
    echo $text;
    exit();
}

For some reason alert message shows [object Object] message instead of "test text". And the weird thing is if I try it like this;

alert(JSON.stringify(message));

it alerts this message;

{"readyState":"4", "responseText":"test text","status":200,"statusText":"OK"}
  • 写回答

2条回答 默认 最新

  • dongmopu6734 2013-08-27 20:38
    关注

    Try this one message.responseText

    $.ajax
    ({
      type: 'POST',
      url: location.href,
      data: {
      'uploaded_data' : 'uploaded_data',
      },
      dataType: 'text',
      success: function(message) {},
      complete: function(message) 
      {
         alert(message.responseText);
      }
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 全志H618ROM新增分区
  • ¥20 jupyter保存图像功能的实现
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况