问题描述
当尝试使用jquery递归在jsfiddle上回显一些html时,我没有得到任何数据.
while trying to echo back some html on jsfiddle using jquery deferreds, I'm not getting any data back.
function showData(data1, data2) {
console.log(data1[0]);
console.log(data2);
}
function method1() {
return $.ajax({
type: "post",
url: "/echo/html/",
data: JSON.stringify("test1"),
dataType: 'html'
});
}
function method2() {
return $.ajax({
type: "post",
url: "/echo/html/",
data: {data: "test2"},
dataType: 'html'
});
}
$.when(method1(), method2()).then(showData);
我不明白我在这里做错了什么.将数据作为对象或作为JSON.stringify
传递,似乎都不起作用. http://jsfiddle.net/VAy5g/
I can't understand what I've done wrong here. Passing the data as an object or as JSON.stringify
, neither seems to work. http://jsfiddle.net/VAy5g/
推荐答案
对此问题有些迟来的回答.
A somewhat belated response to this question.
问题不是您的jQuery.很好唯一的问题是您使用jsFiddle的/echo/html
API.比较您的代码:
The problem is not your jQuery. That works fine. The only problem is your use of jsFiddle's /echo/html
API. Compare your code:
data: {data: "test2"},
工作代码:
data: {html: "test2"},
指定响应的属性是data.html
,而不是data.data
.
The property that specifies the response is data.html
, not data.data
.
此版本的代码可以正常工作.
这篇关于jsfiddle-在以下情况下使用jquery返回html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!