使用 jquery 将 FQL 结果发布到 cakephp 控制器的最佳方法
我有一个 fql 结果,它是一个 javascript 对象,如下所示:
[{"name":"3904","fql_result_set":[{"like_count":"0"}]},{"name":"7617","fql_result_set":[{"like_count":"0"}]},{"name":"9674","fql_result_set":[{"like_count":"0"}]}]
我找不到将其传递到我的控制器的方法,以便能够从我的控制器访问数据并回显给我作为一个简单的测试。
我可以将 {"name":john","id":2323}
等简单的 json 字符串发送到控制器,并使用 $this->params[form ]['name'] & $this->params['form']['id]
在控制器中,但我不确定如何格式化 FQL 结果以将其发送到我的蛋糕控制器通过 ajax 并使用检索它我需要对其进行字符串化还是应该迭代并创建一个更简单的 json 字符串?
I have an fql result that's a javascript object that looks like this:
[{"name":"3904","fql_result_set":[{"like_count":"0"}]},{"name":"7617","fql_result_set":[{"like_count":"0"}]},{"name":"9674","fql_result_set":[{"like_count":"0"}]}]
I can't find a a way to pass it to my controller so as to be able to access the data from my controller and echo back to me as a simple test.
I can send simple json strings like {"name":john","id":2323}
to the controller and have it send it back by using $this->params[form]['name'] & $this->params['form']['id]
in the controller, but I'm not sure how to format the FQL result to send it to my cake controller via ajax and retrieve it using cakephp. Do I need to stringify it or should I make iterate through and create a json simpler json string?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够通过向整个 json 对象添加一个名称来解决这个问题,以便在发布它时
对于控制器来说,可以使用名称/值约定来访问它。在本例中,名称是数据,值是数组。如果不将名称添加到对象中,对象中的数据将无法完整地到达控制器。
现在可以像这样访问它:
$this->data[0]['name']
,或$this->data[0]['fql_resut_set'][ 0]['like_count']
。I was able to solve this by adding a name to the entire json object so that when it get's posted
to the controller, it could be accessed using the name/value convention. In this case, the name is data and the value is the array. Without adding the name to the object, the data in the object would not get to the controller intact.
So it can now be accessed like so:
$this->data[0]['name']
, or$this->data[0]['fql_resut_set'][0]['like_count']
.