javascript - Handle remote CGI script's response in AJAX -


i'm trying handle response of cgi script (located on remote machine) in php generated html page on apache server i'm working on.

a little background first. user upon accessing webpage asked login using username , password (htaccess). upon login, username , site-code of user in organization determined. example let:

username: user sitecode: in88 

i'm handling cgi call in html form follows:

<form method="post" action="http://path/scriptname.cgi?userid=user&siteid=in88&type=desktop">     <input type="submit" value="create account"></input>     <div id="result"></div>     </form> 

and handling response follows (the script return simple text output saying success, if account created, or skipped, if users account exists):

<script> $(function() {         $('form').submit(function(event) {                 event.preventdefault();          $.ajax({                 url: 'http://path/script.cgi?userid=user&siteid=in88&type=desktop',                 type: 'post',                 datatype: 'text',                 beforesend: function() {                         $('#result').html("sending request server ...");                 },                 success: function (response) {                         console.log('success response: ' + response);                         var text = "account registration status: " + response;                         $('#result').html(text);                 },                 error: function(response){                         console.log('error response: ' + response);                         $('#result').html("account registration status: " + response);                 }         }); }); }); </script> 

the error i'm getting is:

xmlhttprequest cannot load http://path/script.cgi?userid=user&siteid=in88&type=desktop. no 'access-control-allow-origin' header present on requested resource. origin 'mymachinename' therefore not allowed access.

now error, clear me there access issue , server machine cgi script located not giving access http requests originating machine. tried adding following header information in ajax request:

'access-control-allow-origin': '*'

but didn't work either. appreciated.

thanks.

your url incorrect. http://path/script going try , hit server named path. since ajax code loaded server (e.g. example.com), you're trying cross-domain request. browser won't bother trying initiate http request, it'll rejected without ever hitting network.

for simple ajax requests, url can literally url: '/path/script?....', , browser fill in http://example.com automatically, if had <img src="kittens.jpg"> in html.

that or add in name of server, it's url: 'http://example.com/path/etc...'


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -