简体   繁体   中英

Redirecting to new page by having form submit on body onload

I am doing an ajax call to a 3rd party web service which returns a complete HTML set in one of the field which comes as a response. The returned HTML has a logic where in onload event of body it will submit a form to their servlet.

This is my web service response :

<rewardresponse>
  <redirectHTML>
   <html>
   <head></head>
   <body onload="document.forms.ssoForm.submit();">
     <form id="ssoForm" action="www.thirdparty.com/SSO/SingleSignOnServlet">
       <input type="hidden" name="customerID" value="1202020"/>
     </form>
   </body>
   </html>
  </redirectHTML>
</rewardresponse>

This is my ajax call :

       $.ajax({
          url     : '/rewards/sso',
          type    : 'GET',
          dataType:'json',
          success : function(response){
                  //document.write(response.redirectHTML);
                  document.documentElement.innerHTML = response.redirectHTML;
          }
       })

I have tried document.write and innerHTML thing, both are not working. It is changing the html content but redirect is not happening.

Please suggest.

Instead of making an ajax request, load the /rewards/sso call into an iframe. When it returns html, it will trigger the body onload

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM