jQuery没有识别Symfony JSON? [英] jQuery not recognizing Symfony JSON?

查看:106
本文介绍了jQuery没有识别Symfony JSON?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Symfony获取我的JSON数据,但它似乎没有正常工作。以下是symfony代码的片段:

I'm trying to get my JSON data from Symfony but it doesn't seem to be working right. Below is the snippet of symfony code:

$this->getResponse()->setHttpHeader('Content-Type', 'application/json; charset=utf-8');
return $this->renderPartial('listJsonResponse', 
array('jsonSlots' => json_encode($this->jsonQuery)));

以上工作正常并且达到部分。我所偏爱的就是:

The above works fine and hits the partial. All that is in my partial is this:

<?php echo $jsonSlots ?>

现在根据Firebug,这会得到正确的填充。以下是回复的副本

Now according to Firebug this gets populated properly. Below is a copy of the response


[{" id":" 1"," schedule_day":" Mon" ," START_TIME":" 09:00:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 2英寸},{" ID":" 2英寸," schedule_day" ;:"星期一及QUOT;," START_TIME":" 09:15:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":0"},{" ID"":" 3英寸," schedule_day":"星期一及QUOT;," START_TIME":" 09:30:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ; ID":" 4英寸," schedule_day":"星期一及QUOT;," START_TIME":" 09:45:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 5英寸," schedule_day":"星期一及QUOT;," START_TIME":" 10:00:00& QUOT;," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 6英寸," schedule_day":"星期一及QUOT;," START_TIME" ;: " 10:15:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 7英寸;," schedule_day":"星期一及QUOT; ," START_TIME":" 10:30:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 8英寸," schedule_day" ;:"星期一及QUOT;," START_TIME":" 10:45:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":0"},{" ID"":" 9"," schedule_day":"星期一及QUOT;," START_TIME":" 11:00:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ; ID":" 10"," schedule_day":"星期一及QUOT;," start_时间":" 11:15:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 11 QUOT;," schedule_day":" ;星期一及QUOT;," START_TIME":" 11:30:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 12英寸;, " schedule_day":"星期一及QUOT;," START_TIME":" 11:45:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID" :" 13 QUOT;," schedule_day":"星期一及QUOT;," START_TIME":" 12:00:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"} ,{" ID":" 14';," schedule_day":"星期一及QUOT;," START_TIME":" 12:15:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT" :" 0"},{" ID":" 15"," schedule_day" ;:"星期一及QUOT;," START_TIME":" 12:30:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":0"},{" ID"":" 16 QUOT;," schedule_day":"星期一及QUOT;," START_TIME":" 12:45:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ; ID":" 17"," schedule_day":"星期一及QUOT;," START_TIME":" 13:00:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 18 QUOT;," schedule_day":"星期一及QUOT;," START_TIME":" 13:15:00"," concurrent_appointments":" 2英寸," ; CURRENTCOUNT":" 0"},{" ID":" 19 QUOT;," schedule_day":"星期一及QUOT;," START_TIME":" 13:30:00"," concurrent_appointments" ;: " 2英寸," CURRENTCOUNT":" 0"},{" ID":" 20 "," schedule_day":"星期一及QUOT;," START_TIME":" 13:45:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ; ID":" 21"," schedule_day":"星期一及QUOT;," START_TIME":" 14:00:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 22"," schedule_day":"星期一及QUOT;," START_TIME":" 14:15:00"," concurrent_appointments":" 2英寸," ; CURRENTCOUNT":" 0"},{" ID":" 23"," schedule_day":"星期一及QUOT;," START_TIME":" 14:30:00"," concurrent_appointments" ;: " 2英寸," CURRENTCOUNT":" 0"},{" ID":" 24英寸;," schedule_day":"星期一及QUOT;," START_TIME":" 14:45:00" ," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0&q UOT;},{" ID":" 25"," schedule_day":"星期一及QUOT;," START_TIME":" 15:00:00"," concurrent_appointments":" 2英寸," ; CURRENTCOUNT":" 0"},{" ID":" 26"," schedule_day":"星期一及QUOT;," START_TIME":" 15:15:00"," concurrent_appointments" ;: " 2英寸," CURRENTCOUNT":" 0"},{" ID":" 27"," schedule_day":"星期一及QUOT;," START_TIME":" 15:30:00" ," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 28"," schedule_day":"星期一及QUOT;," START_TIME":" 15:45:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 29"," schedule_day":"星期一及QUOT;," ; START_TIME":" 16:00:00"," concurrent_appointments":" 2英寸,&现状吨; CURRENTCOUNT":" 0"},{" ID":" 30英寸;," schedule_day":"星期一及QUOT;," START_TIME":" 16:15:00"," concurrent_appointments" :" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 31 QUOT;," schedule_day":"星期一及QUOT;," START_TIME":" 16:30:00" ;," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 32"," schedule_day":"星期一及QUOT;," START_TIME":" ; 16:45:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 33"," schedule_day":"星期一及QUOT ;, " START_TIME":" 17:00:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 34"," schedule_day" :"星期一及QUOT;," START_TIME":" 17:15:00"," concurrent_appoint发言:":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 35 QUOT;," schedule_day":"星期一及QUOT;," START_TIME":" 17:30 :00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 36英寸;," schedule_day":"星期一及QUOT;," START_TIME" :17:45:00,concurrent_appointments:2,currentCount:" 0"}]

[{"id":"1","schedule_day":"Mon","start_time":"09:00:00","concurrent_appointments":"2","currentCount":"2"},{"id":"2","schedule_day":"Mon","start_time":"09:15:00","concurrent_appointments":"2","currentCount":"0"},{"id":"3","schedule_day":"Mon","start_time":"09:30:00","concurrent_appointments":"2","currentCount":"0"},{"id":"4","schedule_day":"Mon","start_time":"09:45:00","concurrent_appointments":"2","currentCount":"0"},{"id":"5","schedule_day":"Mon","start_time":"10:00:00","concurrent_appointments":"2","currentCount":"0"},{"id":"6","schedule_day":"Mon","start_time":"10:15:00","concurrent_appointments":"2","currentCount":"0"},{"id":"7","schedule_day":"Mon","start_time":"10:30:00","concurrent_appointments":"2","currentCount":"0"},{"id":"8","schedule_day":"Mon","start_time":"10:45:00","concurrent_appointments":"2","currentCount":"0"},{"id":"9","schedule_day":"Mon","start_time":"11:00:00","concurrent_appointments":"2","currentCount":"0"},{"id":"10","schedule_day":"Mon","start_time":"11:15:00","concurrent_appointments":"2","currentCount":"0"},{"id":"11","schedule_day":"Mon","start_time":"11:30:00","concurrent_appointments":"2","currentCount":"0"},{"id":"12","schedule_day":"Mon","start_time":"11:45:00","concurrent_appointments":"2","currentCount":"0"},{"id":"13","schedule_day":"Mon","start_time":"12:00:00","concurrent_appointments":"2","currentCount":"0"},{"id":"14","schedule_day":"Mon","start_time":"12:15:00","concurrent_appointments":"2","currentCount":"0"},{"id":"15","schedule_day":"Mon","start_time":"12:30:00","concurrent_appointments":"2","currentCount":"0"},{"id":"16","schedule_day":"Mon","start_time":"12:45:00","concurrent_appointments":"2","currentCount":"0"},{"id":"17","schedule_day":"Mon","start_time":"13:00:00","concurrent_appointments":"2","currentCount":"0"},{"id":"18","schedule_day":"Mon","start_time":"13:15:00","concurrent_appointments":"2","currentCount":"0"},{"id":"19","schedule_day":"Mon","start_time":"13:30:00","concurrent_appointments":"2","currentCount":"0"},{"id":"20","schedule_day":"Mon","start_time":"13:45:00","concurrent_appointments":"2","currentCount":"0"},{"id":"21","schedule_day":"Mon","start_time":"14:00:00","concurrent_appointments":"2","currentCount":"0"},{"id":"22","schedule_day":"Mon","start_time":"14:15:00","concurrent_appointments":"2","currentCount":"0"},{"id":"23","schedule_day":"Mon","start_time":"14:30:00","concurrent_appointments":"2","currentCount":"0"},{"id":"24","schedule_day":"Mon","start_time":"14:45:00","concurrent_appointments":"2","currentCount":"0"},{"id":"25","schedule_day":"Mon","start_time":"15:00:00","concurrent_appointments":"2","currentCount":"0"},{"id":"26","schedule_day":"Mon","start_time":"15:15:00","concurrent_appointments":"2","currentCount":"0"},{"id":"27","schedule_day":"Mon","start_time":"15:30:00","concurrent_appointments":"2","currentCount":"0"},{"id":"28","schedule_day":"Mon","start_time":"15:45:00","concurrent_appointments":"2","currentCount":"0"},{"id":"29","schedule_day":"Mon","start_time":"16:00:00","concurrent_appointments":"2","currentCount":"0"},{"id":"30","schedule_day":"Mon","start_time":"16:15:00","concurrent_appointments":"2","currentCount":"0"},{"id":"31","schedule_day":"Mon","start_time":"16:30:00","concurrent_appointments":"2","currentCount":"0"},{"id":"32","schedule_day":"Mon","start_time":"16:45:00","concurrent_appointments":"2","currentCount":"0"},{"id":"33","schedule_day":"Mon","start_time":"17:00:00","concurrent_appointments":"2","currentCount":"0"},{"id":"34","schedule_day":"Mon","start_time":"17:15:00","concurrent_appointments":"2","currentCount":"0"},{"id":"35","schedule_day":"Mon","start_time":"17:30:00","concurrent_appointments":"2","currentCount":"0"},{"id":"36","schedule_day":"Mon","start_time":"17:45:00","concurrent_appointments":"2","currentCount":"0"}]

请注意,如果我取出Content / Type标题,它会略有变化。我得到与上面相同的响应选项卡,但也有一个html选项卡,上面解析为html。显示如下:

Note if I take out the Content/Type header it changes slightly. I get the same response tab as above but also an html tab with the above parsed into html. Which shows like this:


[{" id":" 1"," schedule_day":" Mon"," ; START_TIME":" 09:00:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 2英寸},{" ID":" 2英寸," schedule_day" ;: "星期一及QUOT;," START_TIME":" 09:15:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 3英寸," schedule_day":"星期一及QUOT;," START_TIME":" 09:30:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID" ;:" 4英寸," schedule_day":"星期一及QUOT;," START_TIME":" 09:45:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0" },{" ID":" 5英寸," schedule_day":"星期一及QUOT;," START_TIME":" 10:00:00",&曲OT; concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 6英寸," schedule_day":"星期一及QUOT;," START_TIME":" 10 :15:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 7英寸;," schedule_day":"星期一及QUOT;," START_TIME":" 10:30:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 8英寸," schedule_day":" ;星期一及QUOT;," START_TIME":" 10:45:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 9" ;, " schedule_day":"星期一及QUOT;," START_TIME":" 11:00:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID" :" 10"," schedule_day":"星期一及QUOT;," START_TIME" ;:" 11:15:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 11 QUOT;," schedule_day":"星期一及QUOT;," START_TIME":" 11:30:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 12英寸," ; schedule_day":"星期一及QUOT;," START_TIME":" 11:45:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID" ;: " 13 QUOT;," schedule_day":"星期一及QUOT;," START_TIME":" 12:00:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"}, {" ID":" 14';," schedule_day":"星期一及QUOT;," START_TIME":" 12:15:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT" ;: " 0"},{" ID":" 15"," schedule_day":" M上"," START_TIME":" 12:30:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 16"," ; schedule_day":"星期一及QUOT;," START_TIME":" 12:45:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID" ;: " 17"," schedule_day":"星期一及QUOT;," START_TIME":" 13:00:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"}, {" ID":" 18 QUOT;," schedule_day":"星期一及QUOT;," START_TIME":" 13:15:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT" ;: " 0"},{" ID":" 19 QUOT;," schedule_day":"星期一及QUOT;," START_TIME":" 13:30:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 20",&q UOT; schedule_day":"星期一及QUOT;," START_TIME":" 13:45:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID" :" 21"," schedule_day":"星期一及QUOT;," START_TIME":" 14:00:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"} ,{" ID":" 22"," schedule_day":"星期一及QUOT;," START_TIME":" 14:15:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT" :" 0"},{" ID":" 23"," schedule_day":"星期一及QUOT;," START_TIME":" 14:30:00"," concurrent_appointments":" 2英寸;," CURRENTCOUNT":" 0"},{" ID":" 24英寸;," schedule_day":"星期一及QUOT;," START_TIME":" 14:45:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{&q UOT; ID":" 25"," schedule_day":"星期一及QUOT;," START_TIME":" 15:00:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0 QUOT;},{" ID":" 26"," schedule_day":"星期一及QUOT;," START_TIME":" 15:15:00"," concurrent_appointments":" 2英寸;, " CURRENTCOUNT":" 0"},{" ID":" 27"," schedule_day":"星期一及QUOT;," START_TIME":" 15:30:00"," concurrent_appointments" :" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 28"," schedule_day":"星期一及QUOT;," START_TIME":" 15:45:00" ;," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 29"," schedule_day":"星期一及QUOT;," START_TIME":" ; 16:00:00"," concurrent_appointments":" 2英寸,"当前计数":" 0"},{" ID":" 30英寸;," schedule_day":"星期一及QUOT;," START_TIME":" 16:15:00"," concurrent_appointments":" ; 2英寸," CURRENTCOUNT":" 0"},{" ID":" 31 QUOT;," schedule_day":"星期一及QUOT;," START_TIME":" 16:30:00" ;, " concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 32"," schedule_day":"星期一及QUOT;," START_TIME":" 16 :45:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 33"," schedule_day":"星期一及QUOT;," START_TIME":" 17:00:00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 34"," schedule_day":" ;星期一及QUOT;," START_TIME":" 17:15:00"," concurrent_appointments&现状吨;:" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 35 QUOT;," schedule_day":"星期一及QUOT;," START_TIME":" 17:30 :00"," concurrent_appointments":" 2英寸," CURRENTCOUNT":" 0"},{" ID":" 36英寸;," schedule_day":"星期一及QUOT;," START_TIME" :17:45:00,concurrent_appointments:2,currentCount:" 0"}]

[{"id":"1","schedule_day":"Mon","start_time":"09:00:00","concurrent_appointments":"2","currentCount":"2"},{"id":"2","schedule_day":"Mon","start_time":"09:15:00","concurrent_appointments":"2","currentCount":"0"},{"id":"3","schedule_day":"Mon","start_time":"09:30:00","concurrent_appointments":"2","currentCount":"0"},{"id":"4","schedule_day":"Mon","start_time":"09:45:00","concurrent_appointments":"2","currentCount":"0"},{"id":"5","schedule_day":"Mon","start_time":"10:00:00","concurrent_appointments":"2","currentCount":"0"},{"id":"6","schedule_day":"Mon","start_time":"10:15:00","concurrent_appointments":"2","currentCount":"0"},{"id":"7","schedule_day":"Mon","start_time":"10:30:00","concurrent_appointments":"2","currentCount":"0"},{"id":"8","schedule_day":"Mon","start_time":"10:45:00","concurrent_appointments":"2","currentCount":"0"},{"id":"9","schedule_day":"Mon","start_time":"11:00:00","concurrent_appointments":"2","currentCount":"0"},{"id":"10","schedule_day":"Mon","start_time":"11:15:00","concurrent_appointments":"2","currentCount":"0"},{"id":"11","schedule_day":"Mon","start_time":"11:30:00","concurrent_appointments":"2","currentCount":"0"},{"id":"12","schedule_day":"Mon","start_time":"11:45:00","concurrent_appointments":"2","currentCount":"0"},{"id":"13","schedule_day":"Mon","start_time":"12:00:00","concurrent_appointments":"2","currentCount":"0"},{"id":"14","schedule_day":"Mon","start_time":"12:15:00","concurrent_appointments":"2","currentCount":"0"},{"id":"15","schedule_day":"Mon","start_time":"12:30:00","concurrent_appointments":"2","currentCount":"0"},{"id":"16","schedule_day":"Mon","start_time":"12:45:00","concurrent_appointments":"2","currentCount":"0"},{"id":"17","schedule_day":"Mon","start_time":"13:00:00","concurrent_appointments":"2","currentCount":"0"},{"id":"18","schedule_day":"Mon","start_time":"13:15:00","concurrent_appointments":"2","currentCount":"0"},{"id":"19","schedule_day":"Mon","start_time":"13:30:00","concurrent_appointments":"2","currentCount":"0"},{"id":"20","schedule_day":"Mon","start_time":"13:45:00","concurrent_appointments":"2","currentCount":"0"},{"id":"21","schedule_day":"Mon","start_time":"14:00:00","concurrent_appointments":"2","currentCount":"0"},{"id":"22","schedule_day":"Mon","start_time":"14:15:00","concurrent_appointments":"2","currentCount":"0"},{"id":"23","schedule_day":"Mon","start_time":"14:30:00","concurrent_appointments":"2","currentCount":"0"},{"id":"24","schedule_day":"Mon","start_time":"14:45:00","concurrent_appointments":"2","currentCount":"0"},{"id":"25","schedule_day":"Mon","start_time":"15:00:00","concurrent_appointments":"2","currentCount":"0"},{"id":"26","schedule_day":"Mon","start_time":"15:15:00","concurrent_appointments":"2","currentCount":"0"},{"id":"27","schedule_day":"Mon","start_time":"15:30:00","concurrent_appointments":"2","currentCount":"0"},{"id":"28","schedule_day":"Mon","start_time":"15:45:00","concurrent_appointments":"2","currentCount":"0"},{"id":"29","schedule_day":"Mon","start_time":"16:00:00","concurrent_appointments":"2","currentCount":"0"},{"id":"30","schedule_day":"Mon","start_time":"16:15:00","concurrent_appointments":"2","currentCount":"0"},{"id":"31","schedule_day":"Mon","start_time":"16:30:00","concurrent_appointments":"2","currentCount":"0"},{"id":"32","schedule_day":"Mon","start_time":"16:45:00","concurrent_appointments":"2","currentCount":"0"},{"id":"33","schedule_day":"Mon","start_time":"17:00:00","concurrent_appointments":"2","currentCount":"0"},{"id":"34","schedule_day":"Mon","start_time":"17:15:00","concurrent_appointments":"2","currentCount":"0"},{"id":"35","schedule_day":"Mon","start_time":"17:30:00","concurrent_appointments":"2","currentCount":"0"},{"id":"36","schedule_day":"Mon","start_time":"17:45:00","concurrent_appointments":"2","currentCount":"0"}]

我知道JSON函数正在命中,但它没有解析成功函数并提醒我任何类型的数据。 JavasScript如下所示,包含在jquery ready标签中

I know the JSON function is hitting, but it isn't parsing the success function and alerting me any sort of data. the JavasScript is shown below and is wrapped in a jquery ready tag

$.getJSON('/frontend_dev.php/module/listJSONSlots', function(data) {
    alert(data);
});

为什么我无法收到警报的任何想法?

Any ideas why I can't get to the alert?

推荐答案

你不需要渲染模板,你可以跳过它并直接从你的动作中返回一些东西。试试这个:

You do not need to render a template, you can skip that and directly return something from your action. Try this:

return $this->renderText(json_encode($this->jsonQuery));

这篇关于jQuery没有识别Symfony JSON?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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