簡體   English   中英

jQuery URL在Firefox上獲取錯誤

[英]jQuery URL Get error on Firefox

任何人都可以指出為什么我的JavaScript函數落入錯誤函數而不是成功函數? Ubuntu上的Firefox

$(document).ready(function() {
        console.log( "Start" );
        $.ajax({ type: "GET", dataType: "html", url: "http://slashdot.org",
        error: function(request, status) {
            console.log("Error");
        },
        success: function(data) {
            console.log("Sucess");
        }
        });
            console.log( "End" );
        });

由於相同來源的安全限制 ,您無法向當前網頁的域以外的域發出ajax調用。

可能的解決方法取決於您的實際問題:

  1. 在您的域上構建一個服務器代理,用於從您的其他站點獲取網頁,以便您可以將請求發送到您自己的域。

  2. 使用iframe顯示其他域中的內容。

這是跨域策略的常見問題。 如果您使用的是jQuery Ajax,則可以使用JSONP進行跨域查詢。 文件來自http://api.jquery.com/jQuery.ajax/

 $.ajax({ type: "GET", dataType: "json", url: "https://api.instagram.com/v1/tags/stackoverflow/media/recent?client_id=0324ff3396ef4ab49697505678e734f5&callback=?",
      error: function(request, status) {
           console.log(request, status);
      },
      success: function(data) {
           console.log(data);
      }
 });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM