Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

json - JSONP request: "Resource interpreted as Script but transferred with MIME type text/html"

I'm trying to do my first cross request with JSONP to get a banner from an external URL.

<script type="text/javascript">
    function handleResponse(json){
    var data = JSON.parse(json);
    alert(data);
    }
</script>
<script src="http://lujanventas.com/plugins/banners/?callback=handleResponse"></script>

This code I think it's a pretty basic JSONP request. My problem is that is that I get the error: "Resource interpreted as Script but transferred with MIME type text/html".

I haven't modified the file in any way to prepare it for the request. (I believe I must modify it somehow but have no idea what to do).

What must I do to get the file with no problems?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I had the same issue with my jsonp requests. I got

Resource interpreted as Script but transferred with MIME type text/plain

, but once I set the response "Content-Type" header to "text/javascript", I get it resolved. But this could only be done if you control the server. So either tell lujanventas.com to try to change the "ContentType" header, or ignore it :)

Cheers!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...