我有一个ASP.NET MVC Web API,我从$ .ajax()方法调用。从我的API返回正确的JSON,但该对象不可访问。尝试登录的价值为 “姓名” 当我收到的控制台的错误是:
Uncaught TypeError: Cannot read property 'Name' of undefined
JSON:
[{"id":2,"Name":"thom","Picture":"thom.jpg","About":"I'm a guy. This is my profile. Now quit staring and get out of here.","Location":"London"}]
的jQuery:
$.ajax({
cache:false,
type: 'GET',
dataType: 'json',
url: 'http://localhost:3235/Users/searchUsers?callback=?&searchString=' + searchString,
complete: function (data) {
console.log(data[0].Name);
}
});
任何帮助,将不胜感激。谢谢!
尝试记录数据是什么。 – 2013-05-02 15:40:36
如果你只是'console.log(data)'来查看返回的内容,而不是仅仅知道'Name'不存在,你能显示什么日志吗? – 2013-05-02 15:40:41
你可能会用'content-type'的'text/html'。在JS中使用'JSON.stringify(result)'或发送正确的头文件和响应。 – 2013-05-02 15:40:52