[英]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.