javascript - Put js variable in jquery -
i trying make code tells status of api
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="generator" content="coffeecup html editor (www.coffeecup.com)"> <meta name="dcterms.created" content="sun, 21 jul 2013 22:43:28 gmt"> <meta name="description" content=""> <meta name="keywords" content=""> <title></ title> <script type="text/javascript"> <!-- var xhrprint="" function blahblahblah(par){ var xhr = new xmlhttprequest() xhr.open("get" par) xhr.send() xhrprint = xhr.statustext } var por= prompt("type in website") blahblahblah(por) $(document).ready(function(){ $("#marker").append() }); --> </script > <!--[if ie]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> </head> <body> <h1 id="marker"></h1> </body> </html>
the basic code auto generated
pass append()
make <p>
contains text variable xhrprint
?
xhrprint
, if request synchronous, that's bad solution.
if we're going use jquery, let's drop manual xmlhttprequest
, try jquery of it.
that can done $.get
. pass url , callback, , it'll call callback result when it's done. in callback, can append data quite easily:
var url = prompt("what website?", ""); $.get(url, function(data) { $("#marker").append(data); });
if don't care appending , fine replacing content, load
easier:
var url = prompt("what website?", ""); $("#marker").load(url);
Comments
Post a Comment