admin管理员组

文章数量:1400024

My ajax call hits the controller and fetches a plete 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(pleteHtmlPage) {
        alert("Success");
        $("#html").load(pleteHtmlPage);
    },
    error : function() {
        alert("error in loading");
    }

});

My ajax call hits the controller and fetches a plete 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(pleteHtmlPage) {
        alert("Success");
        $("#html").load(pleteHtmlPage);
    },
    error : function() {
        alert("error in loading");
    }

});
Share Improve this question asked Jun 24, 2015 at 4:37 Android MasonAndroid Mason 4691 gold badge7 silver badges17 bronze badges 7
  • 2 Why don't you use window.location.href = '/newpage'; to redirect to the page? – Cymen Commented Jun 24, 2015 at 4:40
  • two questions: 1. did you see the alert("Success")? 2. could you please add your html code, specially #html part? – Mehdi Commented Jun 24, 2015 at 4:46
  • have you ever HEARD about LINKS? – madalinivascu Commented Jun 24, 2015 at 4:49
  • this is not how you use .load(), please read the jQuery API doc again – Rick Su Commented Jun 24, 2015 at 4:52
  • On success Redirect the page – Vishal Patel Commented Jun 24, 2015 at 4:53
 |  Show 2 more ments

2 Answers 2

Reset to default 2

This should do:

$.ajax({

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

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

});

You can try this,

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

into your success.

本文标签: javascriptLoad ajax success data on new pageStack Overflow