getJSON不起作用 [英] getJSON does not work
本文介绍了getJSON不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在main.php中的代码是这样的:
My code in main.php is like this:
$(document).ready(function(){
$.getJSON('abc.php?valueOne=value1&valueTwo=value2', function(data){
alert(data);
}
});
在abc.php中有文本值和数字作为结果我想在main.php中显示
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
需要一个JSON响应,所以你应该有这种PHP代码:
$.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",
));
然后,在JavaScript中:
Then, inside JavaScript:
function(data) {
alert(data.one);
alert(data.two);
}
这篇关于getJSON不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文