javascript - Send data to php using JSON (Crossdomain) -


my code server1 , php code server2. both servers separate. problem code ?

var hr = new xmlhttprequest(); hr.open("post", "http://www.3675design.com/clients/hl/developers/cyber/itgetbetter/email/index.php", true); hr.setrequestheader("content-type", "application/x-www-form-urlencoded"); hr.onreadystatechange = function () {     if (hr.readystate == 4 && hr.status == 200) {         var data = json.parse(hr.responsetext);         (var obj in data) {             document.getelementbyid("conformation_and_error_header").innerhtml = "video";             document.getelementbyid("conformation_and_error_body").innerhtml = "share yor video";              $(document).ready(function () {                 $(".inline_popup_display_2").colorbox({                     inline: true,                     width: "50%"                 });             });         }     } } hr.send("name=" + name + "&mail=" + mail + "&youtube=" + youtube + "&comments=" + comments + ""); 

in php code, u can add response header allow cross domain access:

header("access-control-allow-origin:*"); 

in js code, if u want post json string instead of k-v, should change request header:

//hr.setrequestheader("content-type", "application/x-www-form-urlencoded"); hr.setrequestheader("content-type", "application/json"); 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -