I've hit a brickwall with some ridulously simple jquery and i'm about to flip my desk so I hope someone can help. I've been trying to figure this out for hours and it makes no sense to me.
I'm simply trying to return a PHP variable to an via an Ajax call:
This is my js:
This is my PHP:
- var user=1;
- type: "POST",
- dataType: "json",
- data: "user",
- url: "test.php",
- alert('hello '+result['success']);
- return false;
My index page links to the jquery library as follows:
- $my_data=array("failed"=> 'No!','success'=>'Hooray!');
- echo json_encode($my_data);
And to my js:
The Ajax is called when I click the button of an html form, but it doesn't give me the alert. If II comment out the dataType:json line the alert does appear albeit with the variable data missing.
It could not be any more elementary could it? Yet this has caused me endless wasted hours trying hundreds of combinations but no matter what I do I can't get the alert to popup with the data returned from the php.