简体   繁体   English

“jquery.jsonp.js”GET有效。 POST PUT DELETE OPTIONS怎么样?

[英]“jquery.jsonp.js” GET works. What about POST PUT DELETE OPTIONS?

jsonp http methods besides GET (POST, PUT, OPTIONS, DELETE) 除了GET(POST,PUT,OPTIONS,DELETE)之外的jsonp http方法

Using jquery built-in $.ajax method looks like this 使用jquery内置的$ .ajax方法如下所示

$(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", 只想提请注意线型type: "GET",使用$ .ajax执行http PUT只需更改type: "PUT",

This code example comes from JSON parsing from cross domain using jquery ajax 此代码示例来自使用jquery ajax从跨域进行JSON解析

Not using $.ajax 不使用$ .ajax

Using google-code's jquery.jsonp https://github.com/jaubourg/jquery-jsonp 使用谷歌代码的jquery.jsonp https://github.com/jaubourg/jquery-jsonp

Here is an example of using jquery.jsonp.js with the GET method 以下是将jquery.jsonp.js与GET方法一起使用的示例

$.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. 如何做一个GET jsonp请求不是我的问题。

In $.jsonp, would like to perform the other http methods: PUT POST DELETE OPTIONS ... ? 在$ .jsonp中,想要执行其他http方法:PUT POST DELETE OPTIONS ...? Does $.jsonp support the type="PUT", ? $ .jsonp是否支持type="PUT", ,?

It's not mentioned at all in the docs: API.md and TipsAndTricks.md Nor in the source code. 在文档中根本没有提到它:API.md和TipsAndTricks.md也没有在源代码中提及。

UPDATE UPDATE

@ohgodwhy There is a hack (iframes / Proxy) to get POST 2 work cross domains. @ohgodwhy有一个hack(iframes / Proxy)来获得POST 2工作跨域。 Using PUT/POST/DELETE with JSONP and jQuery 使用PUT / POST / DELETE与JSONP和jQuery

@thefrontender Linked article suggests looking into, "Cross-Origin Resource Sharing (CORS)" @thefrontender链接文章建议调查,“跨源资源共享(CORS)”

CORS support by browser http://caniuse.com/cors 浏览器http://caniuse.com/cors支持CORS

Same article also says, "You could encode JSON as a URL parameter, but shame on you for even thinking that." 同一篇文章还说,“你可以将JSON编码为一个URL参数,但是即使你这么想也会感到羞耻。” In all of history, shame never stopped anyone? 在历史的所有历史中,羞耻从未阻止任何人? Simple, lazy, and in limited cases gets the job done. 简单,懒惰,在有限的情况下完成工作。

Thx 4 everyones help ... Thx 4每个人都帮忙......

JSON-P works by injecting a script tag into your document: it is not a traditional XHR request. JSON-P的工作原理是将脚本标记注入到文档中:它不是传统的XHR请求。

So you can usually only perform GET requests. 所以你通常只能执行GET请求。 You can NOT perform PUT requests. 您无法执行PUT请求。

More details in this write-up: http://johnnywey.wordpress.com/2012/05/20/jsonp-how-does-it-work/ 本文的更多细节: http//johnnywey.wordpress.com/2012/05/20/jsonp-how-does-it-work/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM