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;

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 个解决方案



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


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



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