jQuery 使用jquery ajax调用将json数据加载到div
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18548017/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 21:55:33 来源:igfitidea点击:
Loading json data to div using jquery ajax call
提问by Paul Phoenix
Can anyone please tell me what is wrong with the given below code. I am trying to load data in a div using json call.
谁能告诉我下面给出的代码有什么问题。我正在尝试使用 json 调用在 div 中加载数据。
function getData() {
$.ajax({
url: "http://echo.jsontest.com/key/value/one/two",
type: "get",
dataType: "JSON"
}, function(data){
$('#99').append(JSON.stringify(data));
});
return false;
}
It would be great if someone can put some light on $.ajax, $.get, $.post and $.getJSON
如果有人可以点亮,那就太好了 $.ajax, $.get, $.post and $.getJSON
回答by Louay Alakkad
You're mixing $.get
and $.ajax
你在混合$.get
和$.ajax
Use this instead:
改用这个:
$.ajax({
url: "http://echo.jsontest.com/key/value/one/two",
dataType: "json"
}).success(function(data){
$('#data').append(JSON.stringify(data));
});