有没有办法在 CodeIgniter 中使用 jQuery JSONP 而不打开查询字符串?
我的代码如下:
$.getJSON("http://xx.xx.x.x/directory/index.php?c=json&m=get_listing&jsoncallback=?", { action:'listings' }, function(data) {
// code
});
这工作得很好。但现在我在使用其他库时遇到了很多麻烦,这些库在启用查询字符串时不友好。如果我关闭查询字符串,并将上面的 URL 更改为:
http://xx.xx.x.x/directory/index.php/json/get_listing/jsoncallback=?
不起作用。关于解决方法有什么想法吗?
编辑:
当我关闭查询字符串并使用它时:
http://xx.xx.x.x/directory/index.php/json/get_listing/jsoncallback=?
Safari 的控制台显示以下错误:
GET http://xx.xx.x.x/directory/index.php/json/get_listing/jsoncallback=jQuery17102770626428537071_1329431463691?action=categories&_=1329431463695 400 (Bad Request)
My code is as follows:
$.getJSON("http://xx.xx.x.x/directory/index.php?c=json&m=get_listing&jsoncallback=?", { action:'listings' }, function(data) {
// code
});
This works just fine. But now I'm having a lot of troubles with other libraries that don't play friendly with query strings being enabled. If I turn query strings off, and change the URL above to:
http://xx.xx.x.x/directory/index.php/json/get_listing/jsoncallback=?
Doesn't work. Any ideas on a work around?
EDIT:
When I turn off query string, and use this:
http://xx.xx.x.x/directory/index.php/json/get_listing/jsoncallback=?
Safari's console shows the following error:
GET http://xx.xx.x.x/directory/index.php/json/get_listing/jsoncallback=jQuery17102770626428537071_1329431463691?action=categories&_=1329431463695 400 (Bad Request)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
修好了。这有效:
Fixed it. This works:
例如,如果最后一段是 7,则 url 必须组成为:
If the last segment is for instance 7, the url must be composed as:
还有人对此感兴趣吗?
我刚刚在我的网站上进行了结合 Angular、Jsonp 和 CodeIgniter 的测试,效果非常好。
但我担心安全隐患。
如果有人对此有建议,我将不胜感激,
而不是将参数直接发送到控制器网址,如下所示:
将它们作为查询发送到网址中,并使用控制器中的相应方法:
在我的 Angular 工厂中,URL 字符串被设置为查询
希望它有帮助。
Is someone still interested in this?
I just made a test on my website to combine Angular, Jsonp and CodeIgniter and it works great.
But i'm concerned by the security implications.
If someone have a recommendation on this i will be grateful
Instead of sendig the paramteres directly to the controller url as here:
Send them in the url as a query and get them with the respective method in the controller:
And in my Angular factory the URL string is set as a query
Hope it helps.