简体   繁体   中英

Can't send Jquery Ajax post to work using JSON

I need to sync some data from my Phonegap app back to the server. I have a PHP script on the server to receive the data and I need to be able to post some values to it from my App.

I am storing my data in a SQLite database and I want to output it and AJAX it to the server.

I don't seem to be getting any data sent to the PHP script and the onSuccess function is just returning a copy of the data it's sending rather than a response from the server. If I console.log the currentRow object, it returns a string of data for each row as expected.

Can someone point me in the right direction?

Here is the database query and the AJAX call...

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);
});

I think the problem was actually in the php. I stripped it all back, sent one row at a time and retuned a JSON string instead of text and all is well now

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM