Tom
Tom

Reputation: 6707

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);  

Upvotes: 1

Views: 2563

Answers (1)

andersonbd1
andersonbd1

Reputation: 5386

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"});

Upvotes: 5

Related Questions