Reputation: 53
I am trying to pass data to php code using ajax. but I cant get is success.
<?php
$message = $_POST["message"];
$buyer_name = $_POST["buyer_name"];
$order_number = $_POST["order_number"];
$account = $_POST["account"];
$designer = $_POST["designer"];
echo $message; ?>
this is my js code.
var formdata = {buyer_name:byrName,order_number:orderNum.trim(),account:account,designer:'admin',message:'testing'}
if(autoMode){
$.ajax({
type:'POST',
url: 'msgHandle.php',
data: formdata,
contentType: false,
cache: false,
processData: false,
beforeSend: function() {
},
success: function(data) {
alert(data);
},
error: function() {
alert('failed');
}
});
I have set a button to click and when clicked in runs this ajax code. the output is a alert with empty message. that means it success but seems like variables does not pass correctly to the php code. what is wrong in my code, I can't find.
Upvotes: 1
Views: 163
Reputation: 2584
I tried your code and found that by removing all the three parameters
contentType: false,
cache: false,
processData: false,
From the code posts your data onto another page.
Tried for just a sample array.
Upvotes: 1