-1

I have tried to call some API, and the API gives a html response whose content is an auto submit form by onload. so the question is How to submit the form obtained from the response API?

jquery function :

$.get( "example.html", function( data ) {
    //response is html
});

response from APi (example.html) :

<!DOCTYPE html>
<html>
<head></head>
<body onload="submitOnLoad.submit();">
 <form id="submitOnLoad" method="POST" action="example.com/save">
   <input type="hidden" name="name" value="john" />
   <input type="hidden" name="birthday" value="23-03-2003" />
 </form>
</body>
</html>

Edit : I'm sorry I was not clear. I need other solution.

taufiq
  • 23
  • 6

1 Answers1

1

First, jQuery is just a library of functions to make coding easier, especially the short hand for browser api's. Second, you wouldn't want to get an html page via ajax, because the browsers can anyways handle the request over a webserver. Ajax is mostly used with Restful Server end points for Data exchange, rather than getting entire HTML files. However, if you are only playing around to learn, try this snippet. be sure to pass the html string.

$.get( "example.html", function( data ) {
    $('body').html(<response html string>)
});
Salus Sage
  • 678
  • 3
  • 16