Cordova ajax呼叫在真实设备上失败并在模拟器中工作

时间:2015-05-01 12:19:11

标签: ajax cordova

我有一个带有一些Ajax调用的Cordova应用程序。一切正常,但是我上传了一些通过相机拍摄的照片(通过base64编码)。

问题是在Genymotion模拟器(Nexus 5)上调用工作正常,另一方面在真正的Nexus 5上,调用失败并出现错误500,我真的无法弄清楚原因。

以下是Ajax调用的代码:

 $('.add-coupon').on('click', function() {
    var dt = {
        "api_token": localStorage['api_token'],
        "title": localStorage['c_title'],
        "description": localStorage['c_description'],
        "start_price": localStorage['c_price'],
        "third_level_category": localStorage['c_third'],
        "main_attachments": localStorage['image_0'],
        "post_attachments_1": localStorage['image_1'],
        "post_attachments_2": localStorage['image_2'],
        "post_attachments_3": localStorage['image_3']
    };
    $.ajax({
        url: 'http://www.XXXXXXXXXXXXXXX.com:8000/api/v1/upload',
        type: 'POST',
        data: JSON.stringify(dt),
        cache: true,
        async: true,
        success: function(data) {
            alert('ok');
            window.location = 'index-shop.html';
        },
        error: function(event, jqXHR, ajaxSettings, thrownError) {
            alert('[event:' + event + '], [jqXHR:' + jqXHR.responseText + '], [ajaxSettings:' + ajaxSettings + '], [thrownError:' + thrownError + '])');
        }
    });
 });

正如您所看到的,在请求期间没有发生任何特殊情况,我缺少什么?

如果我使用postman(Chrome插件)使用相同的数据拨打电话,一切正常!

编辑:如果我没有拍任何照片(所以main_attachmends和所有post_attachments都是空的)调用工作。只有当我拍摄不起作用的图像时才会这样。

1 个答案:

答案 0 :(得分:0)

我通过添加以下代码解决了这个问题:Getting error "exceeded available parameter key space"?

显然模拟器图像非常小,一切正常,但是对于普通图像,我收到以下错误:

App 15424 stderr: [ 2015-05-04 13:28:38.2529 15508/0x00000001a22140(Worker 1) utils.rb:84 ]: *** Exception RangeError in Rack application object (exceeded available parameter key space) (process 15508, thread 0x00000001a22140(Worker 1))