Load ajax success data on new page

11,456

Solution 1

This should do:

$.ajax({

url : '/newpage',
type : 'POST',
data : requestString,
dataType : "text",
processData : false,
contentType : false,
success : function(completeHtmlPage) {
    alert("Success");
    $("html").empty();
    $("html").append(completeHtmlPage);

},
error : function() {
    alert("error in loading");
}

});

Solution 2

You can try this,

my_window = window.open("");
my_window.document.write(completeHtmlPage);

into your success.

Share:
11,456
Android Mason
Author by

Android Mason

Updated on June 26, 2022

Comments

  • Android Mason
    Android Mason almost 2 years

    My ajax call hits the controller and fetches a complete JSP page on success. I was trying to load that data independently on a new page rather than within some element of the existing page. I tried loading it for an html tag but that didn't work either. I tried skipping the success function but it remained on the same page without success data. My ajax call is made on clicking a normal button in the form and the code looks like as shown below.

    $.ajax({
    
        url : '/newpage',
        type : 'POST',
        data : requestString,
        dataType : "text",
        processData : false,
        contentType : false,
        success : function(completeHtmlPage) {
            alert("Success");
            $("#html").load(completeHtmlPage);
        },
        error : function() {
            alert("error in loading");
        }
    
    });
    
    • Cymen
      Cymen almost 9 years
      Why don't you use window.location.href = '/newpage'; to redirect to the page?
    • Mehdi
      Mehdi almost 9 years
      two questions: 1. did you see the alert("Success")? 2. could you please add your html code, specially #html part?
    • madalinivascu
      madalinivascu almost 9 years
      have you ever HEARD about LINKS?
    • Neverever
      Neverever almost 9 years
      this is not how you use .load(), please read the jQuery API doc again
    • Vishal Patel
      Vishal Patel almost 9 years
      On success Redirect the page
    • Android Mason
      Android Mason almost 9 years
      @Cymen i can't use that as my the newpage requires dynamic data which is bein handled by controller right now.
    • Android Mason
      Android Mason almost 9 years
      @VishalPatel i dont want to redirect to a new page. i want to load the page that i got in success
  • Android Mason
    Android Mason almost 9 years
    Thanks. Option 1 works perfect for me. Though i use it like this instead $("html").empty(); $("html").append(completeHtmlPage). The option 2 seems to be an incorrect solution as it loads my HtmlContent in the Url resulting in page not found error.
  • Clyde Winux
    Clyde Winux almost 9 years
    that means completeHtmlPage is not URL but the content..if you found my answer correct please accept it as an answer..:)
  • Android Mason
    Android Mason almost 9 years
    Yes you are right, i have mentioned the same in my question, completeHtmlPage is HTML content. Thanks for the answer. can you please remove the option 2 so that i can accept this as the answer?