Reputation: 1144
I have the following ajax ,on which im trying to post the dataString
as a parameter to the php file.
I have tried putting dataString
inside xhr.send(dataString);
.But it didnt work out.Is there any way around?
dataString = txCryptData;
var xhr = new XMLHttpRequest();
var params="data="+dataString;
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
alert(xhr.responseText);
}
}
xhr.open('POST', 'tokenize.php', true);
xhr.send();
In the php I tried $_POST['params']; to fetch the value posted by the ajax req
Upvotes: 0
Views: 1335
Reputation: 133
xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xhr.send(params); You may have to add these lines to your js snippet
Upvotes: 0
Reputation: 2783
$.ajax({
type: 'POST',
// make sure you respect the same origin policy with this url:
url: 'youUrl',
data: {
'Joo': 'bar',
'ca$libri': 'no$libri' // $ sign in the parameter name seems unusual, I would avoid it
},
success: function(msg){
alert('Value' + msg);
}
});
Upvotes: 1
Reputation: 1468
In PHP use this to get the string sent with ajax :
$data = file_get_contents("php://input");
And in JS :
dataString = txCryptData;
var xhr = new XMLHttpRequest();
var params="data="+dataString;
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status==200) {
alert(xhr.responseText);
}
}
xhr.open('POST', 'tokenize.php', true);
xhr.send(params);
Upvotes: 1