php - AJAX post to external url -


this question has answer here:

i trying post data ajax external url following code:

$(document).ready(function(){     $('.submit_button').click(function() {         $.ajax({                 type : 'post',                 url : 'http://site.com/post.php',                 datatype : 'text',                 data: $("#infoform").serialize()         }).done(function(results) {                     alert(results);         });         event.preventdefault();     }); }); 

but getting following error:

xmlhttprequest cannot load http://site.com/post.php. origin null not allowed access-control-allow-origin.

i have added the following line htaccess file on server

header set access-control-allow-origin * 

would able tell me doing wrong , how can post data external url?

is external url yours? if no, it's not possible. if yes have return following headers on domain:

access-control-allow-origin: http://your.domain.com 

or if want allow domains:

access-control-allow-origin: * 

more info can found here: https://developer.mozilla.org/en-us/docs/http/access_control_cors

if it's not domain have create proxy, create php file gets content need domain. , ajax request own domain.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -