简体   繁体   English

请求具有文本/纯MIME类型的JSONP

[英]Request JSONP with text/plain MIME Type

I'm trying to use JSONP to request a feed on another domain. 我正在尝试使用JSONP请求另一个域上的feed。 I know that the content type should be JSON or JavaScript, but it is text/plain and I don't have control over the server so I can't change the header. 我知道内容类型应该是JSON或JavaScript,但它是文本/纯文本,并且我无法控制服务器,因此无法更改标头。 How can I get an AJAX call to work? 如何获得AJAX呼叫才能正常工作?

Here is what I have so far - 这是我到目前为止的内容-

function asdf() {
    $.ajax({
        url: "http://example.com/path/to/sharepoint/_vti_bin/listdata.svc/TestCalendar/$count",
        jsonp: "callback",
        dataType: "jsonp",
        contentType: "text/plain",

        // work with the response
        success: function( response ) {
            console.log( response ); // server response
        }
    });
}

If I just try a regular request, obviously I just get a CORS error. 如果我只是尝试一个常规请求,显然我只会收到CORS错误。

XMLHttpRequest cannot load http://example.com/path/to/sharepoint/_vti_bin/listdata.svc/TestCalendar/ $count. XMLHttpRequest无法加载http://example.com/path/to/sharepoint/_vti_bin/listdata.svc/TestCalendar/ $ count。 No 'Access-Control-Allow-Origin' header is present on the requested resource. 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 Origin ' http://example.com ' is therefore not allowed access. 因此,不允许访问来源“ http://example.com ”。 The response had HTTP status code 401. 响应的HTTP状态码为401。

Try to execute directly your URL in a browser to be sure that all is working fine 尝试在浏览器中直接执行您的URL,以确保一切正常
After that, try with this JQuery configuration: 之后,尝试使用以下JQuery配置:

$.ajax({
        url        : "YOUR_URL",
        dataType   : 'jsonp',
        crossDomain: true,
        type       : 'POST',
        timeout    : 30000, // in milli seconds
        cache      : false
        success:function(response) {
            console.log(response);
        }
    });

暂无
暂无

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

相关问题 资源解释为脚本,但使用MIME类型text / plain传输 - 用于本地文件 - Resource interpreted as Script but transferred with MIME type text/plain - for local file Chrome错误-资源被解释为脚本,但以MIME类型的文本/纯文本传输 - Chrome Error - Resource interpreted as Script but transferred with MIME type text/plain AWS Cloudfront 将 javascript 模块作为错误的 MIME 类型(“Text/Plain”)提供服务 - AWS Cloudfront serving javascript modules as wrong MIME type( "Text/Plain") AWS Load Balancer - 'text/plain' 不是有效的 JavaScript MIME 类型 - AWS Load Balancer - 'text/plain' is not a valid JavaScript MIME type js警告:资源被解释为脚本,但以MIME类型text / plain传输 - js warning: Resource interpreted as Script but transferred with MIME type text/plain Cloudfront 将 javascript 文件作为文本/纯文本的 Mime 类型提供服务 - Cloudfront serving javascript files as Mime type of Text/plain 启用了严格的 mime 类型检查,拒绝执行来自 ' 的脚本<url> ' 它的 mime 类型 ('text/plain') 是不可执行的,并且</url> - strict mime type checking is enabled, refused to execute script from '<url>' its mime type ('text/plain') is not executable, and 什么mime类型是纯文本? - What mime types are plain text? JSONP脚本返回MIME类型错误 - JSONP script returning MIME Type error $ .ajax表单使用JSONP提交给Google文档:“资源解释为脚本,但以MIME类型text / html传输” - $.ajax form submit to Google Docs using JSONP: “Resource interpreted as Script but transferred with MIME type text/html”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM