Jquery Ajax从POST调用设置内容
我需要执行此调用,并根据收到的响应设置页面内容(完整文档)。这句话有点不对劲: $(document.documentElement).innerHTML=response.responseText; 可能是什么Jquery Ajax从POST调用设置内容,jquery,html,ajax,json,post,Jquery,Html,Ajax,Json,Post,我需要执行此调用,并根据收到的响应设置页面内容(完整文档)。这句话有点不对劲: $(document.documentElement).innerHTML=response.responseText; 可能是什么 $.ajax({ type: "POST", url: "/sakila", data: userAsJson, success: function(response){ $(document.documentElement).inner
$.ajax({
type: "POST",
url: "/sakila",
data: userAsJson,
success: function(response){
$(document.documentElement).innerHTML = response.responseText;
return response;
}
});
请尝试以下jQuery方式:
$(document.documentElement).innerHTML(response.responseText);
如果要使用Jquery执行此操作,请执行以下操作:
$("#yourcontainer").html(response.responseText);
document.getElementById("#yourcontainer").innerHtml = response.responseText;
并使用Javascript:
$("#yourcontainer").html(response.responseText);
document.getElementById("#yourcontainer").innerHtml = response.responseText;
首先,
返回响应
不能那样返回。您可以使用resposne调用将值传递到该函数的函数。AJAX是异步的(异步JavaScript和XML),因此返回对您没有帮助。也可以使用.html()
而不是本机DOM方法,除非您知道自己在做什么
您可能不想使用,因为这样会返回文档的根元素<代码>。使用除此之外的HTML元素,并通过jQuery选择它
function successCallback() {
$(document.documentElement).html(this.responseText);
}
$.ajax({
type: "POST",
url: "/sakila",
data: userAsJson,
success: function(response){
// either do everything in here, or pass the object to a function not both
$(document.documentElement).html(response.responseText);
// OR
successCallback.call(response);
}
});
试试这个(如果response
是一个json对象)——
dataType:“json”
。如果你能告诉我们你的json结构<代码>控制台日志(响应)代码>它给了你什么。尝试输入success方法并查看浏览器控制台。