$.ajax({
url: 'test.php',
type: 'GET',
dataType: 'json',
data: "last_name=SMITH&first_name=JOHN&middle_name=J",
contentType: "application/json; charset=utf-8",
success: function(response) {
var len = response.length;
for (var i = 0; i < len; i++) {
var name = response[i].LASTNAME + ", " + response[i].FIRSTNAME + " " + response[i].MIDDLE
var sysid = response[i].ORDERID
$("<li></li>")
.html("<a href='result.php?orderid=" + orderid + "'>" + name + "</a>")
.insertAfter($("#questions-divider"));
$("#questions").listview("refresh");
}
}
});
});
This works with GET. I tried it with post and it failed. I have _POST in my php page. I changed the data parameter to be:
data: '{ "last_name": "SMITH", "first_name": "JOHN", "middle_name": "J" }',
But this fails also (with get and post). My php page returns that it can't find last_name in my payload. $_POST['last_name']
never gets the data in my php page. Send it with GET and it works (I changed my php to use $_GET
for testing then back to $_POST
).
edit: I tried this but it did not help: Cant get jQuery ajax POST to work
edit: also: jquery $.post empty array
edit: I was able to get like this. Don't know why the formatted data fails:
//data: '{ "last_name": "SMITH", "first_name": "JOHN", "middle_name": "J" }',
data: "last_name=SMITH&first_name=JOHN&middle_name=J",
//contentType: "application/json; charset=utf-8",
contentType: "application/x-www-form-urlencoded",