jQuery AJAX函數拋出未知錯誤。

[英]jQuery AJAX function throwing unknown error


I have the following function in a jQueryMobile page running in chrome and firefox. This same function runs without error in a PhoneGap + jQueryMobile app in iOS Simulator, but for some reason when it's run in the browser the error function gets called.

我在運行chrome和firefox的jQueryMobile頁面中有以下功能。這個函數在iOS模擬器中的PhoneGap + jQueryMobile應用程序中沒有出錯,但由於某些原因,當它在瀏覽器中運行時,錯誤函數會被調用。

textStatus returns null and errorThrown returns "error"

textStatus返回null, error拋出返回“error”

$.ajax({type : "GET", 
        url : "https://itunes.apple.com/lookup?id=356541460&entity=album", 
        data : {get_param : "results"}, 
        dataType : "json", 
        error : function(jqXHR, textStatus, errorThrown) {alert(errorThrown); alert(textStatus);}, 
        success : function(data) {
            $.each(data, function(index, element) {
                $.each(this, function(index, element) {
                    if (element.wrapperType === "collection") {
                        $("#albums-list").append("<li><a id='albums-a-" + element.collectionId + "' href='#album-details'><img src='" + element.artworkUrl100 + "' />" + element.collectionName + "</a></li>"); 
                        $("#albums-a-" + element.collectionId).bind('click', function(index) {
                            Albums.AlbumID = element.collectionId;
                        });
                    }
                });
            });
            $("#albums-list").listview("refresh");
        }
});

Could this be a bug? Is this not designed to run in a browser?

這可能是個錯誤嗎?這不是設計在瀏覽器中運行的嗎?

Is there another function that I could use that would not have this result?

是否有另一個函數我可以用它來得到這個結果?

1 个解决方案

#1


2  

If this is a cross domain request (likely), you need to add a callback for jsonp to the URL:

如果這是一個跨域請求(可能),您需要為jsonp添加一個回調到URL:

url : "https://itunes.apple.com/lookup?id=356541460&entity=album&callback=?", 

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2013/01/31/721073631ff0b993fce7fcba19fb59d6.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com