" jquery.jsonp.js" GET工作. POST PUT DELETE OPTIONS怎么样? [英] "jquery.jsonp.js" GET works. What about POST PUT DELETE OPTIONS?
问题描述
除了GET(POST,PUT,OPTIONS,DELETE)之外的jsonp http方法
使用jquery内置的$ .ajax方法看起来像这样
$(document).ready(function() {
$.ajax({
type: "GET",
url: "http://myurl.com/webservice&callback=?",
...
});
只想引起注意type: "GET",
行
使用$ .ajax执行http PUT只需更改type: "PUT",
此代码示例来自使用jquery ajax从跨域进行JSON解析
不使用$ .ajax
使用Google代码的jquery.jsonp https://github.com/jaubourg/jquery-jsonp
这是将jQuery方法与jQuery方法结合使用的示例
$.jsonp({
cache: false,
url: 'http://www.mydomain.com/logicalurl/2/',
callbackParameter: 'callback',
timeout: 10000,
success: function(json, textStatus, xOptions) {
myglob = json;
MyModulePatternObject.initNew(json);
},
error: function (xOptions, textStatus) {
console.log("fail");
}
});
这很好用.不是我的问题,如何执行GET jsonp请求.
在$ .jsonp中,想要执行其他http方法:PUT POST DELETE OPTIONS ...? $ .jsonp是否支持type="PUT",
?
在文档中完全没有提到它:API.md和TipsAndTricks.md在源代码中也没有.
更新
@ohgodwhy 有一个hack(iframe/代理)可让POST 2跨域工作. 通过JSONP和jQuery使用PUT/POST/DELETE >
@thefrontender 链接的文章建议调查跨源资源共享(CORS)"
浏览器CORS支持 http://caniuse.com/cors
同一篇文章还说:您可以将JSON编码为URL参数,但即使想到了也感到羞耻."在整个历史上,羞耻从未阻止任何人?简单,懒惰,并且在有限的情况下可以完成工作.
谢谢4个人...
JSON-P的工作原理是将脚本标签注入文档中:这不是传统的XHR请求.
因此,您通常只能执行GET请求.您无法执行PUT请求.
本文中的更多详细信息: http ://johnnywey.wordpress.com/2012/05/20/jsonp-how-does-it-work/
jsonp http methods besides GET (POST, PUT, OPTIONS, DELETE)
Using jquery built-in $.ajax method looks like this
$(document).ready(function() {
$.ajax({
type: "GET",
url: "http://myurl.com/webservice&callback=?",
...
});
Only want to draw attention to the line type: "GET",
With $.ajax performing a http PUT would be simply change type: "PUT",
This code example comes from JSON parsing from cross domain using jquery ajax
Not using $.ajax
Using google-code's jquery.jsonp https://github.com/jaubourg/jquery-jsonp
Here is an example of using jquery.jsonp.js with the GET method
$.jsonp({
cache: false,
url: 'http://www.mydomain.com/logicalurl/2/',
callbackParameter: 'callback',
timeout: 10000,
success: function(json, textStatus, xOptions) {
myglob = json;
MyModulePatternObject.initNew(json);
},
error: function (xOptions, textStatus) {
console.log("fail");
}
});
This works perfectly. How to do a GET jsonp request is not my question.
In $.jsonp, would like to perform the other http methods: PUT POST DELETE OPTIONS ... ? Does $.jsonp support the type="PUT",
?
It's not mentioned at all in the docs: API.md and TipsAndTricks.md Nor in the source code.
UPDATE
@ohgodwhy There is a hack (iframes / Proxy) to get POST 2 work cross domains. Using PUT/POST/DELETE with JSONP and jQuery
@thefrontender Linked article suggests looking into, "Cross-Origin Resource Sharing (CORS)"
CORS support by browser http://caniuse.com/cors
Same article also says, "You could encode JSON as a URL parameter, but shame on you for even thinking that." In all of history, shame never stopped anyone? Simple, lazy, and in limited cases gets the job done.
Thx 4 everyones help ...
JSON-P works by injecting a script tag into your document: it is not a traditional XHR request.
So you can usually only perform GET requests. You can NOT perform PUT requests.
More details in this write-up: http://johnnywey.wordpress.com/2012/05/20/jsonp-how-does-it-work/
这篇关于" jquery.jsonp.js" GET工作. POST PUT DELETE OPTIONS怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!