Reputation: 39
Why would this not work for me ? It's an AJAX POST request to a php script, the script has been tested and works fine with fixed variables.
The request is as follows
$.ajax({
type: "POST",
url: url,
data:{serial:id},
contentType:"application/json; charset=utf-8",
dataType: "json",
success: function(data){}
My php is
<?php
header("Access-Control-Allow-Origin: *");
header('Content-type: application/json');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo 'POSTed';
} //to test post
$account = $_POST['serial'];
....etc
which is followed my a MySQL request.
And from my console everything looks fine, except I get " Undefined index: serial" as my response. I have tried constructing my POST variables many different ways. It come from source which when viewed shows the correct variable.
var id = localStorage.userAccount;
Upvotes: 0
Views: 681
Reputation: 6736
no need to add contentType:"application/json; charset=utf-8",
in jquery.ajax
. just remove it and then try.
Upvotes: 4