Jquery ajax NEVER passing data to php script
Hello,
It seems my code is NEVER passing data to my php script. I'm using xamp as "server"...
here is how I coded :
-
$.ajax({
url: "phpscript.php",
type : 'POST',
contentType: "application/json; charset=utf-8",
data:{user_id:'user_id'},
dataType : 'text',
success: function(result){
console.log(result);}});
My php is soooo simple
-
<?php
$value = array();
$value['id'] = 'ok' . $_POST['user_id'];
echo json_encode($value);
?>
console.log(result) says :
- <br />
- <b>Notice</b>: Undefined index: user_id in <b>D:\xampp\htdocs\myapp\phpscript.php</b> on line <b>9</b><br />
- {"id":"ok"}
just as if $.ajax was NEVER sending it "data" when calling the php script...
Any help fixing that !? (ps : please don't tell me isset() or empty() because This code is suppose to be (or MUST) populating $_POST with data ....