Heim  >  Artikel  >  Backend-Entwicklung  >  使用jsonp完成跨域请求,但是请求的链接是js文件,请求总是那个js报错,怎莫办?

使用jsonp完成跨域请求,但是请求的链接是js文件,请求总是那个js报错,怎莫办?

WBOY
WBOYOriginal
2016-06-02 11:32:161210Durchsuche

jsonpjs文件php

把链接换成php就没问题。

<code>    $.ajax({        type:'GET',        async:false,        url:"http://app.veishu.com/jsonp/categories/all.js",        dataType:"jsonp",        success:function(data){            alert("success");   //         alert(data[0]);   //         var dataHtml=""   //         for(var i=0; data.length;i++){   //             dataHtml+="<li><a href="#" id=""></a></li>";            }            $(".list").html(dataHtml);        },        error:function(){            alert("ajax is error");        }    });</code>
<code>    这个ajax不会进入error,也没有进入success。    在那个链接的js那报错。    如果把链接换成php会成功进入success。    但这个js文件的链接直接在浏览器打开也没有问题,可以出现json。不知怎么回事?    还有浏览器打开js文件有unicode字符,该怎么转![图片说明](http://img.ask.csdn.net/upload/201504/25/1429951452_561399.png)</code>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn