jQuery ajax数据显示[object Object] [英] jquery ajax data shows [object Object]

查看:1254
本文介绍了jQuery ajax数据显示[object Object]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常基本的ajax调用来提醒服务器报告的数据

I have a very basic ajax call to alert the data that was reported from the server

$.ajax({
       type: "POST",
       url: "/someform/act", //edit utl to url
       data: { changed: JSON.stringify(plainData) }, //edit to include
       success: function(data) {
          alert(data);             //data not $data
       },
       error: function() {
          //error condition code
       }
});

根据jquery网站上有关成功回调上数据字段的 docs ,说返回的数据是来自服务器的数据.但是由于一些奇怪的原因,当我提醒$data时,我得到了[object Object]

According to the docs on the jquery website regarding data field on the success callback, it says that data returned is the data from the server. However for some strange reason when I alert $data, I get [object Object]

我原本希望看到这样的东西,因为那是服务器会发回的东西

I was expecting to see something like this, since that is what the server would send back

<status>0</status>

数据也作为POST传递

data is also passed along as the POST

推荐答案

alert()打印参数的字符串表示形式-因此,如果传递对象,则会得到[object Object].

alert() prints the string representation of the arguments - hence if you pass an object, you'll get [object Object].

要检查数据,请更好地使用console.log(data).

To inspect data, use console.log(data) better.

这篇关于jQuery ajax数据显示[object Object]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆