相关疑难解决方法(0)

如何使用jQuery创建指定contentType的jsonp POST请求?

我需要使用内容类型'application/json'创建一个jsonp POST请求.我可以像这样向服务器发送POST请求:

      jQuery.ajax({
        type: 'POST',
        url: url,
        data: data,
        success: success,
        error: error,
        async: true,
        complete: complete,
        timeout: TIMEOUT,
        scriptCharset: 'UTF-8',
        dataType: 'jsonp',
        jsonp: '_jsonp',
      });
Run Code Online (Sandbox Code Playgroud)

但是一旦我添加该行:contentType: "application/json"它开始将其作为OPTIONS请求而不是POST发送.

如何指定内容类型并仍然以POST方式提交请求?

javascript ajax jquery jsonp http

38
推荐指数
2
解决办法
4万
查看次数

Chrome扩展程序oAuth请求重定向页面未加载

我正在开发与Google日历互动的Chrome扩展程序.我已经开源了,代码可以在GitHub上找到:https://github.com/joshholat/Add-to-Calendar-Chrome-Extension

它需要使用Google的oAuth进行授权才能编辑用户日历.直到最近,这工作正常.然而,有一天它出于某种原因停止了工作.当我执行以下代码时,它会从oauth打开一个新选项卡,该选项卡应该请求权限,但页面永远不会加载,而是冻结"重定向...".因此,我无法授权和测试我的代码.

想法?

var oauth = ChromeExOAuth.initBackgroundPage({
 'request_url': 'https://www.google.com/accounts/OAuthGetRequestToken',
 'authorize_url': 'https://www.google.com/accounts/OAuthAuthorizeToken',
 'access_url': 'https://www.google.com/accounts/OAuthGetAccessToken',
 'consumer_key': 'anonymous',
 'consumer_secret': 'anonymous',
 'scope': 'http://www.google.com/calendar/feeds/',
 'app_name': 'Add Events to Google Calendar'
Run Code Online (Sandbox Code Playgroud)

});

oauth.authorize(function(){alert("auth");});

google-chrome oauth google-chrome-extension

5
推荐指数
1
解决办法
3439
查看次数