I am trying to send a JSON object from an AJAX request to my server.
I do this using jQuery as follows:
$.ajax({ type: "POST", url: settings.ajax.post, dataType: 'json', data: basket.aggregate(Basket.EXPORT_JSON, qty), success: function(data, textStatus, jqXHR) { if (typeof settings.ajax.success == "function") settings.ajax.success(data, textStatus, jqXHR); }, error: function(jqXHR, text, e) { if (typeof settings.ajax.error == "function") settings.ajax.error(jqXHR, text, e); } });
The URL is pointed to this file on the server:
<?php $to = "<my-email-address>"; $subject = "JSON test"; $message = "POST dump:\n\n"; foreach($_POST as $key=>$value) { $message .= $key . ":" . $value; } mail ($to, $subject, $message); exit; ?>
But the POST var seems empty, although in Firebug I see that the correct data was sent to the server:
After sending each request, the ajax error function is called with the undefined error (I think because there was no response from the server? Or I donβt know?)
source share