跨域ajax请求

Rah*_*_RJ 12 html ajax jquery asp.net-ajax

我想从跨域url获取html响应页面.

为此,我使用ajax请求,因为,

 $.ajax({
            type: 'GET',
            url: "http://wcidevapps.com/salescentral/idisk/0001000383/iDisk",
            dataType: "jsonp",
            success: function (response) {
                $(response).find('li a').each(function () {
                    listHref.push($(this).attr('href'));
                });

            }
        });
Run Code Online (Sandbox Code Playgroud)

但在请求后它没有回复任何结果.

rad*_*scu 5

检查文档: http: //api.jquery.com/jQuery.ajax/

crossDomain (默认:同域请求为 false,跨域请求为 true)

类型:布尔值

如果您希望在同一域上强制执行跨域请求(例如 JSONP),请将 crossDomain 的值设置为 true。例如,这允许服务器端重定向到另一个域。(添加版本:1.5)


Abh*_*Das 5

<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
  <script type="text/javascript">
    function NameAFunctionName() {
        $.ajax({
          url: 'http://wcidevapps.com/salescentral/idisk/0001000383/iDisk',
          type: 'GET',
          dataType: 'json',
          headers: {
            //WRITE IF THEIR HAVE SOME HEADER REQUEST OR DATA
          },
          crossDomain: true,
          success: function (data, textStatus, xhr) {
            console.log(data);
          },
          error: function (xhr, textStatus, errorThrown) {
            console.log(errorThrown);
          }
        });
    }   
</script>
Run Code Online (Sandbox Code Playgroud)

  • 为何可行的解释? (4认同)