Reputation: 175
I'm trying to send data from the fields to a PHP file, but it always returns null.
Is my approach correct, or I'm missing something?
Thank in advance. my ajax
$.ajax({
url: '/GetData.php',
dataType: 'json',
type: 'POST',
data: {
a:a,
b:b,
c:c
},
contentType: 'application/json',
success: function(response){
console.log('success '+ JSON.stringify(response));
search_table = JSON.stringify(response)
$('#mytable').html(search_table);
},
error: function(err){
console.log('error '+JSON.stringify(err));
//alert(JSON.stringify(err))
}
});
my GetData.php file
<?php
$a = $_GET["a"];
$b = $_GET["b"];
$c = $_GET["c"];
$remote_url = "http://mydomain/GetDataDetails/?name=".$a."&age=".$b."°ree=".$c;
$opts = array(
'http'=>array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method'=>"GET",
)
);
$context = stream_context_create($opts);
$out=json_decode(file_get_contents($remote_url, false, $context),true);
header('Content-Type: application/json');
echo json_encode($out);
?>
Upvotes: 2
Views: 246
Reputation: 8162
Answer from comment:
$_GET
to $_POST
in PHPcontentType: 'application/json',
from the Ajax requestUpvotes: 1