cross domain - How to get html to return via javascript crossdomain -


i'm using ebay , allow javascript. want return html domain. know jquery , ebay doesn't allow jquery. here how call file in jquery.

var data: { on:1 }; var url = "myfile.php"; jquery.post(url,data,function(response)) { $("#element").html(response); }); 

php

    <?php   echo "<table><tr><th>test</th></tr></table>";     die();     ?> 

how call file in javascript?

as can imagine, sending custom ajax requests pure javascript little trickier. it's not hard. don't need change of php file. equivalent javascript code ajax request is:

ajax example using javascript:

var data = { on: 1 }; // same data parameter on code var xmlhttp; // xmlhttprequest object if (window.xmlhttprequest) {   // code ie7+, firefox, chrome, opera, safari   xmlhttp = new xmlhttprequest(); } else {   // code ie6, ie5   xmlhttp = new activexobject("microsoft.xmlhttp"); } // how access returned data xmlhttp.onreadystatechange=function() {   if (xmlhttp.readystate == 4 && xmlhttp.status == 200) {     // , bind html     document.getelementbyid("element").innerhtml = xmlhttp.responsetext;   } } xmlhttp.open("post","myfile.php",true); // prepares ajax call xmlhttp.setrequestheader("content-type","application/x-www-form-urlencoded"); // sets correct request type post xmlhttp.send(data); // sends request 

update: if you're getting error access control add @ top of php file:

header('access-control-allow-origin: *'); header('access-control-allow-methods: get, post'); 

reference: http://www.w3schools.com/ajax/default.asp

hope answers question.


Comments