如何用ajax响应替换整个html网页? [英] How to replace the entire html webpage with ajax response?

查看:1464
本文介绍了如何用ajax响应替换整个html网页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在讨论具体问题之前,我需要解释一些基本步骤。



首先,相关申请涉及客户在线约会管理。 / p>

客户在填写表格并提供美容中心的护理并提供信息后,请到确认页面。



现在这个页面执行ajax请求以在数据库上存储约会。



如果一切都成功,则会显示一个页面,其中包含约会的详细信息和成功消息。



问题是页面当前只显示在响应中,即在标签网络控制台浏览器中。



所以我的问题很简单: 如何用响应中显示的实际结构替换html页面的整个结构?



我甚至在StackOverflow上发现了很多关于网络的问题。但所有这一切都限于对div的附加。我不需要挂起但也可以替换< html> ,如何重写html页面。我不知道怎么做这个,我需要你的一些建议。



为了完整性,这是回复给我的代码ajax response html:

  $ .ajax({
'type':'POST',
'url':'backend_api / ajax_save_appointment ',
'数据':postData,
'成功':函数(响应)
{
console.log(响应);
},
'error':function(jqXHR,textStatus,errorThrown)
{
console.log('保存约会错误:',jqXHR,textStatus,errorThrown);
}
} );


解决方案

如果您的回复包含 < head> < body> 代码:



$(html)。html(响应);



如果没有,并且它只是内容,那么执行:



$(body)。html(response);


Before going to the specific question I need to explain a few basic steps.

First, the application in question deals with the management of appointments online by customers.

The customer after filling a form with the treatments for the beauty center and providing their information comes to the confirmation page.

Now this page performing an ajax request to store the appointment on the database.

If everything is successful is shown a page containing the details of the appointment with the success message.

The problem is that the page is currently displayed only in the response, that is, in the tab network console browser.

So my question is simple: How can I replace the entire structure of the html page with actual one shown in the response?

I found a lot of questions on the web even on StackOverflow. But all of this is limited on an append to a div. I do not need to hang but also replace the <html>, how to rewrite the html page. I have no idea how to do this and I need some advice from you.

For completeness, this is the code that comes back to me ajax response html:

       $.ajax({
          'type': 'POST',
          'url': 'backend_api/ajax_save_appointment',
          'data': postData,
          'success': function(response)
           {
               console.log(response);
           },
           'error': function(jqXHR, textStatus, errorThrown)
           {
               console.log('Error on saving appointment:', jqXHR, textStatus, errorThrown);    
           }
       });

解决方案

If your response includes the <head> and <body> tags:

$("html").html(response);.

If not, and it's only content, then do:

$("body").html(response);.

这篇关于如何用ajax响应替换整个html网页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆