jQuery将不会从AJAX查询解析我的JSON(jQuery won't parse my JSON from AJAX query)
我难以解析使用jQuery.ajax()从服务器返回的一些JSON数据。
要执行我正在使用的AJAX:
$.ajax({ url: myUrl, cache: false, dataType: "json", success: function(data){ ... }, error: function(e, xhr){ ... } });
如果我返回一个项目的数组,那么它工作正常:
[ { title: "One", key: "1" }, { title: "Two", key: "2" } ]
调用成功函数并接收正确的对象。
但是,当我想要返回一个对象时:
{ title: "One", key: "1" }
调用错误函数,xhr包含“parsererror”。 我已经尝试将JSON包装在服务器上的括号中,然后将其发送出去,但是没有任何区别。 然而,如果我将内容粘贴到Javascript中的一个字符串中,然后使用eval()函数,它将完美地进行评估。
任何想法我做错了什么?
安东尼
I'm having difficulty parsing some JSON data returned from my server using jQuery.ajax()
To perform the AJAX I'm using:
$.ajax({ url: myUrl, cache: false, dataType: "json", success: function(data){ ... }, error: function(e, xhr){ ... } });
And if I return an array of items then it works fine:
[ { title: "One", key: "1" }, { title: "Two", key: "2" } ]
The success function is called and receives the correct object.
However, when I'm trying to return a single object:
{ title: "One", key: "1" }
The error function is called and xhr contains 'parsererror'. I've tried wrapping the JSON in parenthesis on the server before sending it down the wire, but it makes no difference. Yet if I paste the content into a string in Javascript and then use the eval() function, it evaluates it perfectly.
Any ideas what I'm doing wrong?
Anthony
原文:https://stackoverflow.com/questions/249692
最满意答案
primeCounter = 1 candidate = 3 while primeCounter < 1000: isPrime = True counter = 2 while counter < candidate: if candidate%counter == 0: isPrime = False break # <<<<<<<<<<<<<<<<< break here, or the loop will go infinite else: counter = counter + 1 if isPrime == True: print candidate primeCounter = primeCounter + 1 candidate = candidate + 1
primeCounter = 1 candidate = 3 while primeCounter < 1000: isPrime = True counter = 2 while counter < candidate: if candidate%counter == 0: isPrime = False break # <<<<<<<<<<<<<<<<< break here, or the loop will go infinite else: counter = counter + 1 if isPrime == True: print candidate primeCounter = primeCounter + 1 candidate = candidate + 1
相关问答
更多-
嵌套在for循环中的switch指令不起作用[关闭](switch instruction nested in for loop is not working [closed])[2024-01-04]
你的switch语句正在切换字符代码'0' , '1'等,当它应该打开数字 0 ,等等。 此外,您需要在每个部分的末尾添加break语句,否则每个case都会出现在下一部分中。 switch(i) { case 0 : // do something cout << "A" << endl; break; case 1 : // do something else cout << "B" << endl; break; ... -
primeCounter = 1 candidate = 3 while primeCounter < 1000: isPrime = True counter = 2 while counter < candidate: if candidate%counter == 0: isPrime = False break # <<<<<<<<<<<<<<<<< break here, or the loop will ...
-
只需在内部迭代之前初始化i: var a = 0, b = 2048; var i, l = 2048; for(; a < b; a++) { for(i = 0; i < l; i++) { console.log(a, b, i, l); } } Just initialize i every time before inner iteration: var a = 0, b = 2048; var i, l = 2048; for(; a < b; a++) { ...
-
你有没有试过进入第一个阵列? foreach( $groups[0] as $group ) { ?> 如果可能,您可以尝试两个foreach循环: foreach( $groups as $tmp ) { ?> foreach ($tmp as $group) ...
-
消耗完文件后,它就被消耗了。 因此,再次迭代它不会产生任何结果。 >>> for row in input_file: ... print row 1,2,3,... 4,5,6,... etc. >>> for row in input_file: ... print row >>> # Nothing gets printed, the file is consumed 这就是您的代码无法正常工作的原因。 然后,您有三种主要方法: 每次读取文件(I / O操作效率低下); 将其加载到列 ...
-
您没有在entry对象中定位数组,您需要遍历childNodes属性以获取所需的数据。 见下面的例子。 var dataModels = []; dataModels[0] = { childNodes: [] }; dataModels[0].childNodes[0] = { appId: "foo" }; dataModels.forEach(function(entry){ entry.childNodes.forEach(function(childrenEntry ...
-
我的嵌套循环不起作用(My nested loops not working)[2023-07-19]
你忘了使用length属性,因为stringArray是一个数组,你必须使用它的length迭代它。 for (var i = 0; i < stringArray.length; i++) { ................................^^^^ “但是,它没有返回任何东西,即使是console.log也没有返回任何东西。” 要查看更改,您必须按enter键。 var x = event.which || event.keyCode; event.which属性表示按下的特定键或 ... -
您正在错误的地方更新Tcount 。 这样做只是在外循环结束时。 你现在所写的内容会使Tcount每次前进Tcount增加。 当它达到1000步时, Tcount已经是1000。 你的times是10.所以`Tcount> =时间,它不会再次进入外部while循环。 You are updating Tcount at the wrong place. Do it Just at the end of the outer loop. What you have written now makes Tcoun ...
-
for和if / else循环,嵌套的if语句在python中不起作用(for and if/else loop with nested if statement not working in python)[2022-06-29]
然后,我想比较第二个列表第一行的第一个值和下一个列表的第一行,依此类推...... 听起来你想要同时迭代i和j 。 现在,你正在迭代i ,然后停止,然后迭代j 。 尝试使用zip 。 更换 for i in range(1, len(row1)): hi = row1[i][0] for j in range(1,len(row2)): if row2[j][0] == hi: ... -
n个元素的数组具有从0到n-1索引。 n是此类数组的无效索引。 你的指数一个接一个。 它应该是 : for(int a = 0; a
相关文章
更多- jquery与servlet交互的json问题
- AJAX JSON 乱码
- jquery ajax方法url请求action没有返回json数据。
- jQuery使用json的问题,第一次,不知道问题在哪
- Json.Net学习笔记
- AJAX问题
- Json.Net学习笔记
- solr学习笔记二-------solr query查询的参数
- 黑马ajax视频教程
- ajax请求问题,到底哪里错了
最新问答
更多- h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
- 创建一个功能(Create a function)
- 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
- PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
- Qt冻结循环的原因?(Qt freezing cause of the loop?)
- TableView重复youtube-api结果(TableView Repeating youtube-api result)
- 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
- SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
- 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
- 以编程方式创建UITableView(Creating a UITableView Programmatically)
- 如何打破按钮上的生命周期循环(How to break do-while loop on button)
- C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
- 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
- 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
- Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
- 设置kotlin扩展名(Setting a kotlin extension)
- 如何并排放置两个元件?(How to position two elements side by side?)
- 如何在vim中启用python3?(How to enable python3 in vim?)
- 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
- 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
- Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
- dedecms如何安装?
- 在哪儿学计算机最好?
- 学php哪个的书 最好,本人菜鸟
- 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
- 如何覆盖错误堆栈getter(How to override Error stack getter)
- 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
- USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
- 电脑高中毕业学习去哪里培训
- 正则表达式验证SMTP响应(Regex to validate SMTP Responses)