Reputation: 6943
This is how I'm trying to send some data to a php file:
function requestWsList(functionToProcess, me) {
jQuery.support.cors = true;
$.ajax({
crossDomain: true,
traditional: true,
url: urlWS(),
contentType: "text/xml;charset=UTF-8",
dataType: "html",
type: "POST",
data: {name: 'value', anotherName: 'another value'},
processData: false,
success:function(data) {
functionToProcess(data, me);
} });
}
When I call this javascript function, the php request is triggered but I always get an empty array in the php variable $_POST.
What am I doing wrong? What do I have to do to read the "name" and "anotherName" variables in PHP?
Upvotes: 0
Views: 386
Reputation: 764
You set contentType
to "text/xml;charset=UTF-8"
and you are passing a JavaScript object. Just remove this parameter and it should work.
Upvotes: 1
Reputation: 3720
Try to convert your JSON object into a string. For example:
data: '{ "name": "value", "anotherName": "another value" }
If you're using a browser that supports it you can use JSON.stringify()
For example:
data: JSON.stringify({name: 'value', anotherName: 'another value'});
Upvotes: 1