Reputation: 493
I want to send a hash string to my php file. but failed, can anyone help me please?
my javascript is like this:
var hashString = "#support_form";
$.ajax ({
type: "POST",
url:"index.php",
data: hashString,
success: function() {
console.log("message sent!");
}
});
and the php:
<?php
$theHash = $_POST['hashString'];
?>
What should I do? Thanks
Upvotes: 2
Views: 13542
Reputation: 1
var queryString = "f_name=" + f_name + "&l_name=" + l_name + "&contact_no=" + contact_no + "&email=" + email;
$.ajax({
type:'POST',
url:'insert1.php',
data:queryString,
dataType:'json',
success: function(success){
console.log("message sent!");
}
});
Upvotes: 0
Reputation: 3274
$.ajax ({
type: "POST",
url:"index.php",
data: {"hashString":hashString},
success: function() {
console.log("message sent!");
}
});
Upvotes: 0
Reputation: 2333
data key must be of object type This will work for you
var hashString = "#support_form";
$.ajax ({
type: "POST",
url:"index.php",
data: {'hashString':hashString},
success: function() {
console.log("message sent!");
}
});
Upvotes: 0
Reputation: 1733
Your JS should be this:
var hashString = "#support_form";
$.ajax ({
type: "POST",
url:"index.php",
data: {hashString: hashString},
success: function() {
console.log("message sent!");
}
});
Upvotes: 0
Reputation: 15676
Your code would work if you used an object instead of a string. try this:
var hashString = {hashString: "#support_form"};
$.ajax ({
type: "POST",
url:"index.php",
data: hashString,
success: function() {
console.log("message sent!");
}
});
Upvotes: 0
Reputation: 16086
You have to do like this-
$.ajax ({
type: "POST",
url:"index.php",
data: "hashString=value",
success: function() {
console.log("message sent!");
}
});
So you can get the value as-
$theHash = $_POST['hashString'];
echo $theHase; //will print value
Upvotes: 2
Reputation: 33661
You need to specify the name/value for data
data: {hashString:hashString},
Upvotes: 5