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.
Author by
Android Mason
Updated on June 26, 2022Comments
-
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 almost 9 yearsWhy don't you use
window.location.href = '/newpage';
to redirect to the page? -
Mehdi almost 9 yearstwo questions: 1. did you see the
alert("Success")
? 2. could you please add your html code, specially#html
part? -
madalinivascu almost 9 yearshave you ever HEARD about LINKS?
-
Neverever almost 9 yearsthis is not how you use
.load()
, please read the jQuery API doc again -
Vishal Patel almost 9 yearsOn success Redirect the page
-
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 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 almost 9 yearsThanks. 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 almost 9 yearsthat means completeHtmlPage is not URL but the content..if you found my answer correct please accept it as an answer..:)
-
Android Mason almost 9 yearsYes 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?