簡體   English   中英

jQuery getJSON 拋出錯誤?

[英]jQuery getJSON is throwing error?

我在文件中使用 getJSON function 從 api 獲取 JSON 我正在創建,但由於某種原因,getJSON 總是進入我的錯誤處理程序。 javascript 的代碼在這里。 它總是輸入.error function。

    window.onload = function() 
            {
                var data = "store_id=5";
                $.getJSON('http://localhost:81/javascript_plugin/get_store_items', data,
                function(json) {
                  alert(json);
                })
                .success(function() { alert("second success"); })
                .error(function() { alert("error"); })
                .complete(function() { alert("complete"); });
            }

我正在使用 CakePHP 作為我的 api 側面的東西,返回的文件如下所示。 $content_for_layout 包含通過調用“echo $js->object($json);”創建的 JSON object; 使用 jQuery 作為 javascript 引擎。 $json 是 CakePHP 查找調用的結果。

    <?php
         header("Pragma: no-cache");
         header("Cache-Control: no-store, no-cache, max-age=0, must-revalidate"); 
         header('Content-Type: text/x-json'); 
         header("X-JSON: ".$content_for_layout);
         echo $content_for_layout; 
    ?>

在 Firebug 中,響應代碼為 200,header 包含所有顯示的內容,但響應選項卡為空。 任何幫助,將不勝感激。

謝謝

我的問題通過將客戶端 html 文件移動到我的 web 服務器並從那里運行它來解決。 似乎運行 'file://' html 文件將不允許對服務器進行這種類型的調用。 現在 jQuery 的所有版本都可以像所有瀏覽器一樣工作。

暫無
暫無

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

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