I am trying to access another site using a POST request through ajax. So the access flow became :
AJAX request -> PHP CURL -> www.somedomain.com
This is the code for the AJAX request. I guarantee it passes the parameters correctly:
$("#new_access_token").submit(function(ev){
$.ajax({
url : "back_access/access_code.php",
type : "POST",
data: "access_token[app_id]=601&access_token[subscriber_num]="+$("#input-phone-number").val(),
success : function(res){
console.log(res);
}
});
return false;
});
The php curl script is here (access_code.php):
$ch = curl_init();
$url = "http://developer.globelabs.com.ph/oauth/request_authorization";
$data = array("access_token" => array(
'app_id' => $_POST['access_token']['app_id'],
'subscriber_number' => $_POST['access_token']['subscriber_number']
));
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
$result = curl_exec($ch);
print_r($result);
curl_close($ch);
It returns an error of "500". With the correct parameters in terminal curl and Advanced Rest Client, it returns the page. However, this script does not. How do I control the parameters?