My code in main.php is like this:
$(document).ready(function(){
$.getJSON('abc.php?valueOne=value1&valueTwo=value2', function(data){
alert(data);
}
});
in abc.php there are text values and numbers as result which I want to display in main.php
The problem is if it is a number then it is shown in the alert alert(data) else if there are text nothing is working.
Am totally confused about this. Any solutions?
$.getJSON
expects a JSON response, so you should have this kind of PHP code:
header('Content-Type: application/json');
echo json_encode(array(
'one' => "1234",
'two' => "Abcd",
));
Then, inside JavaScript:
function(data) {
alert(data.one);
alert(data.two);
}
Replace
$.getJSON('abc.php?valueOne=value1&valueTwo=value2', function(data){
alert(data);
}
With
$.getJSON('abc.php?valueOne=value1&valueTwo=value2', function(data){
alert(data);
});
there was missing );