簡體   English   中英

appgyver類固醇中的AJAX命令

[英]AJAX command in appgyver steroids

我已經將phonegap項目復制到了類固醇,但是現在我的ajax命令無法正常工作,我完全不知道是什么原因造成的,因此任何建議都可能會有所幫助。

這是導致問題的代碼,它始終會因request.status = 0終止於錯誤:

$.ajax({
        type: "POST",
        url: serverUrl + "login.ajax",
        data: { jsonLogin: JSON.stringify(loginObject), deviceInfo: JSON.stringify(deviceInfo)},
        async: true,
        timeout: 7000,
        cache: false,
        headers: { "cache-control": "no-cache" },
        success: function(data) {
                    ...   
                 },
        error: function(request, status, err) {
            ...
        },
        complete: function(){...}
    });     

AppGyver員工在這里!

config/application.coffee ,是您的steroids.config.location = "http://localhost/index.html"還是只是index.html 類固醇通過本地主機(即電話上的內部Web服務器)提供應用程序文件,而PhoneGap使用文件協議。 使用localhost使WebView強制執行更嚴格的CORS規則,因此您需要對服務器響應的Access-Control-Allow-Origin標頭。 通過File協議提供的HTML文件允許跨域請求通過而沒有CORS標頭。

您可以在以下網址找到帶有AJAX測試的測試項目: https://github.com/appgyver/steroids-runtime-tests

我認為jQuery不會解析json數據,因為您尚未指定dataType

 $.ajax({
            type: "POST",
            url: serverUrl + "login.ajax",
            data: { jsonLogin: JSON.stringify(loginObject), deviceInfo: JSON.stringify(deviceInfo)},
            dataType: json, //Specify data type
            async: true,
            timeout: 7000,
            cache: false,
            headers: { "cache-control": "no-cache" },
            success: function(data) {
                        ...   
                     },
            error: function(request, status, err) {
                ...
            },
            complete: function(){...}
        });  

暫無
暫無

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

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