Ben
Ben

Reputation: 103

AJAX receive html file

I am currently writing a registration form. After the registration is successful, my server sends back an HTML file and I want AJAX to go to the login HTML.

Can someone help me plz with AJAX and JQUERY?

This is what i have:

      $.ajax({
                                      type: 'POST',
                                      url: "http://localhost:3000/UserRegistration",

                                      dataType: 'text',
                                      data: FormData,
                                      success: function (response)  
                                      {}

Also what is dataType? Is that the dataTYpe I am sending to the url or receiiving. Because I am sending a JSON file and receiving an HTML?

Do you also know how I can run a script on the new loaded page? For exampl I want to do load the login page, and append a "TickMark" image to the page: $ApprovedTick.insertAfter( 'header' ); but this wont work on the new page

Upvotes: 2

Views: 5634

Answers (2)

corvallo
corvallo

Reputation: 169

Try by setting dataType to html.

$.ajax({
  type: 'POST',
  url: "http://localhost:3000/UserRegistration",
  dataType: 'html',
  data: FormData,
  success: function (response){
     //supposing you have an html element where you want to append 
     //the response, with an id like appendResponse
     $('#appendResponse').html(response);
  }
});

Upvotes: 0

Vallabha Vamaravelli
Vallabha Vamaravelli

Reputation: 1283

In ajax success event, use window.location to redirect to login page.

enter code here

 success: function (response)  {
      window.location = "http://localhost:3000/login.html";
}

Upvotes: 1

Related Questions