admin管理员组文章数量:1026373
I make a call to the server using ajax and I return the class instance .
My return ajax response looks like follows.
Object { id=1362570046980 , creationDate=1362570046980, type="PUBLIC"}
hOw i can get the values of id , creationDate and type from this object.
I make a call to the server using ajax and I return the class instance .
My return ajax response looks like follows.
Object { id=1362570046980 , creationDate=1362570046980, type="PUBLIC"}
hOw i can get the values of id , creationDate and type from this object.
Share Improve this question edited Mar 6, 2013 at 11:50 Marcel Korpel 21.8k6 gold badges62 silver badges80 bronze badges asked Mar 6, 2013 at 11:45 Saurabh KumarSaurabh Kumar 16.7k49 gold badges142 silver badges219 bronze badges 1- 1 That's a bizarre data format to return. I'd strongly suggest changing the server side to return a standard data format (JSON or XML are probably best) instead. – Quentin Commented Mar 6, 2013 at 11:47
3 Answers
Reset to default 2use .
operator get the objects value.. however the obect which you are gettin is weird.. not JSON.. so make sure it is returning json
say your object is data
alert(data.id) //gives you 1362570046980
alert(data.creationDate) //gives you 1362570046980
alert(data.type) //gives you PUBLIC
Try like this:
var myobject = yourAjaxResponseObject;
alert(myobject.id);
alert(myobject.creationDate);
alert(myobject.type);
Map a variable to your object/response, and access it's properties, etc, in that way as described up above.
You need to specify a callback function in your ajax function to which an object will be passed containing the response.
$.ajax({
type: "POST",
url: "some.php",
data: { name: "John", location: "Boston" },
plete: function(data){ //This is the callback function
alert(data.id);
alert(data.creationDate);
alert(data.type);
}
});
As you can see you can then access the properties in the json using simple dot notation.
I make a call to the server using ajax and I return the class instance .
My return ajax response looks like follows.
Object { id=1362570046980 , creationDate=1362570046980, type="PUBLIC"}
hOw i can get the values of id , creationDate and type from this object.
I make a call to the server using ajax and I return the class instance .
My return ajax response looks like follows.
Object { id=1362570046980 , creationDate=1362570046980, type="PUBLIC"}
hOw i can get the values of id , creationDate and type from this object.
Share Improve this question edited Mar 6, 2013 at 11:50 Marcel Korpel 21.8k6 gold badges62 silver badges80 bronze badges asked Mar 6, 2013 at 11:45 Saurabh KumarSaurabh Kumar 16.7k49 gold badges142 silver badges219 bronze badges 1- 1 That's a bizarre data format to return. I'd strongly suggest changing the server side to return a standard data format (JSON or XML are probably best) instead. – Quentin Commented Mar 6, 2013 at 11:47
3 Answers
Reset to default 2use .
operator get the objects value.. however the obect which you are gettin is weird.. not JSON.. so make sure it is returning json
say your object is data
alert(data.id) //gives you 1362570046980
alert(data.creationDate) //gives you 1362570046980
alert(data.type) //gives you PUBLIC
Try like this:
var myobject = yourAjaxResponseObject;
alert(myobject.id);
alert(myobject.creationDate);
alert(myobject.type);
Map a variable to your object/response, and access it's properties, etc, in that way as described up above.
You need to specify a callback function in your ajax function to which an object will be passed containing the response.
$.ajax({
type: "POST",
url: "some.php",
data: { name: "John", location: "Boston" },
plete: function(data){ //This is the callback function
alert(data.id);
alert(data.creationDate);
alert(data.type);
}
});
As you can see you can then access the properties in the json using simple dot notation.
本文标签: javascriptHow to get the Object atributes from ajax responseStack Overflow
版权声明:本文标题:javascript - How to get the Object atributes from ajax response - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745649997a2161259.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论