I am trying to use jQuery to send an ajax call to a php page but I'm having difficulty. My problem is parsing a variable from PHP to jQuery. I have tried for hours and I have given up. I hope someone will be able to help me!
It's working. And it is writing "Hurray!". I would like it to write my PHP-variable.....
Here is my jquery-script
function saveToDatabase(editableObj,column,id){
// $(editableObj).css("background","#FFF url(html/images/ajaxLoader.gif) no-repeat right");
$.ajax(
{
url: "logic/do.php",
type: "POST",
data: 'action=ajaxSimplePost&column='+column+'&editval='+editableObj.innerHTML+'&id='+id,
success: function(data)
{
// $(editableObj).css("background","#FDFDFD");
Messenger().post(
{
// var message should instead contain: the PHP variable: "myMessage".
message: 'Hurray!',
hideAfter: 3,
type: "error"
})
}
});
}
And here is my PHP code:
if($_POST[action] == "ajaxSimplePost")
{
$myMessage = "Yes it came through.....";
}
console.log(data)?function (data)will contain the response from PHP, e.g. if you doecho "Yes it came through";in PHP then data will have that string in it.