【问题标题】:Can't send Jquery Ajax post to work using JSON无法使用 JSON 发送 Jquery Ajax 帖子以工作
【发布时间】:2013-03-03 23:31:12
【问题描述】:

我需要将一些数据从我的 Phonegap 应用程序同步回服务器。我在服务器上有一个 PHP 脚本来接收数据,我需要能够从我的应用程序向它发布一些值。

我将我的数据存储在 SQLite 数据库中,我想将其输出并 AJAX 将其输出到服务器。

我似乎没有收到任何发送到 PHP 脚本的数据,并且 onSuccess 函数只是返回它正在发送的数据的副本,而不是来自服务器的响应。如果我控制台记录 currentRow 对象,它会按预期为每一行返回一串数据。

有人能指出我正确的方向吗?

这是数据库查询和 AJAX 调用...

var query = "SELECT * FROM fixturesfittings WHERE propertyid = ?;"
localDatabase.transaction(function (trxn) {
    trxn.executeSql(query, [propertyid], function (transaction, thedata) {
        var i = 0,currentRow;
        for (i; i < thedata.rows.length; i++) {
        currentRow = thedata.rows.item(i);

        $.ajax({
            type: "POST",
            url: "http://myserver.com/putData.php",
            cache: false,
            dataType: "text",
            data: currentRow,
            success: function(mydata) {
               $("#resultLog").append(mydata);
            },
            error: function() {
               $("#resultLog").html("Error");
            }


        });
    }

    },errorHandler);
});

【问题讨论】:

  • currentRow 是一组键/值对吗?例如key1=value1&key2=value2
  • 是的,有点像 JSON 字符串 - 每行看起来像这样:{"condition":"Good condition","propertyid":1,"fixture":"Thermostat","type" :" ","category":"Fixtures","color":"White","quantity":"1","roomtype":"Entrance and Hallway","material":"Plastic"}

标签: javascript jquery ajax cordova jquery-mobile


【解决方案1】:

我认为问题实际上出在 php.ini 中。我将其全部剥离,一次发送一行并重新调整 JSON 字符串而不是文本,现在一切都很好

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-26
    • 1970-01-01
    • 1970-01-01
    • 2011-06-23
    • 2011-11-24
    • 1970-01-01
    • 2014-10-10
    相关资源
    最近更新 更多