How to replace the entire html webpage with ajax response?

前端 未结 6 681
难免孤独
难免孤独 2020-12-01 18:38

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 cus

6条回答
  •  無奈伤痛
    2020-12-01 18:47

    @JudgeProhet It seems to me that you do not need AJAX request for this purpose. There is no advantage in doing it this way. If the entire page is updated it could be done by an ordinary HTTP request. If you want to use AJAX, you could simply use JavaScript to redirect to new page, which contains appointment details.

    $.ajax({
       'type': 'POST',
       'url': '/backend/ajax_save_appointment',
       'data': postData,
       'success': function(response)
       {
          console.log(response);
          // redirect browser to new location
          window.location.href = '/backend/appointment_details';
       },
       'error': function(xhr, status, error)
       {
          console.log('Error on saving appointment:', xhr, status, error);
          // display error message to the user
       }
    });
    

提交回复
热议问题