dongma6326 2013-08-27 12:33
浏览 689
已采纳

非常简单的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 12: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条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部