简体   繁体   中英

converting XMLHttpRequest to JSONP

help, I need to change this code to support remote domain access:

document.write(url);
    var http = getHTTPObject();
      http.open("GET", url, true);
      http.onreadystatechange = function() {
          if (http.readyState == 4) {
              parseData(http.responseText);
          }
      }
      http.send(null);  

in your js:

function goRemote(url) {
  var script = document.createElement("script");
  script.src=url;
  document.body.appendChild(script);
}
function parseDate(json) {
  // do your fun here.
}

in your returned js:

parseData({"foo": "bar"});

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