this below code could’nt send data to other server. i want to send "aaa-bbb-ccc" with $.ajax. but after post back userCode thats post empty data from $_POST. sorry for my english
jquery code :
<script type="text/javascript">
$(function(){
$.ajax({
url: "http://www.site.com/index.php",
type: "POST",
dataType: "jsonp",
data: {userCode: "aaa-bbb-ccc"}
}).done(function(data){
alert(data.message);
});
});
</script>
server index.php :
<?php
include_once ('./AFactory.class.php');
$database= new AFactory;
$db=new AFactory();
$link=$db->getDBO();
if ( $_POST['userCode'] == '')
{
$data['success']=false;
$data['message']='ERROR ...';
}
else {
$query=array('id'=>NULL,'userCode'=>$_POST['userCode']);
$sql=$db->insertQuery('`alachiq_takhmis`.`users`',$query);
if ( mysql_query($sql) )
{
$data['success']=true;
$data['message']=$_POST['userCode'];
}
else
{
$data['success']=false;
$data['message']=$_POST['userCode'];
}
}
echo $_GET['callback'] . '('. json_encode($data) . ')';
?>
post back:
({"success":false,"message":'ERROR ...'})
whats my code problem?
JSONP works by injecting a
<script>element with asrcattribute into a document.That can only ever make a GET request.