Jquery has is working before the following line is changed
data: "ID=1",
$ID=$_GET["ID"]
$array=array("$ID",'B',"C");
from
data: "",
$array=array('A','B',"C");
my ajax file
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<button class="ajax_action">click</button>
<script>
$('button.ajax_action').on('click', function (e) {
e.preventDefault();
var target = $(this);
$.ajax({
url: "test.php",
data: "ID=1",
type: 'POST',
dataType: 'json',
success: function (data) {
var name=data[0];
target.html(name);
target.attr('disabled', 'disabled')
},
error: function(jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Not connect.
Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested page not found. [404]');
} else if (jqXHR.status == 500) {
alert('Internal Server Error [500].');
} else if (exception === 'parsererror') {
alert('Requested JSON parse failed.');
} else if (exception === 'timeout') {
alert('Time out error.');
} else if (exception === 'abort') {
alert('Ajax request aborted.');
} else {
alert('Uncaught Error.
' + jqXHR.responseText);
}
}
});
});
</script>
php file test.php (same dir with ajax file)
<?php
$ID=$_GET["ID"]
$array=array("$ID",'B',"C");
echo json_encode($array);
?>
How to make this work with $_GET["ID"], I need to do action according to the ID which is variable according to the product user chosen
and I've read through manual, long ago however manual is ain't easy for a newcomer you know. "You should read manual, idiot" is the worst answer I've ever heard and I can answer every question I don't know with this sentence. @tereško
further changed to following line but still ain't working,
data: {'ID':1},
type: 'POST',
<?php
$ID=$_POST["ID"]
$array=array("$ID",'B',"C");
echo json_encode($array);
?>