jQuery $.post function not hitting the server? failed error response -


i'm trying access control processor has built in web server. based on specific values programmed controller able trigger actions through website resides on built in server using jquery or js. i'm having issue though jquery post command. when use goggle's rest plugin works , response. ideas?

function getvariablevaluesbyname(name) {     $.post("http://10.10.254.11/rpc/", {         method: "getvariablevaluesbyname",         param1: name,         encoding: "2"     }).done(function (data) {         data = string(data);         var info = data.responsetext;         alert(info);     }).fail(function (data) {         data = string(data);         alert("error " + data)     }).always(function (data) {         data = string(data);         alert("just in case " + data);     }); } 

some additional examples last function example assumes i've created xmlhttp object.

function getvariablevaluesbyname(name) {  $.ajax({ type: "post", url: "http://10.10.254.11/rpc/", data: { method: "getvariablevaluebyname", param1: "vol_bar", encoding: "2" } }).done(function( msg ) {     alert( "data saved: " + msg ); }).fail(function(msg) {     alert("error " + msg) }); }  function getvariablevaluesbyname(name) {  xmlhttp.open("post","http://10.10.254.11/rpc/",false); var thestring = "method=getvariablevaluebyname&param1=" + name; xmlhttp.setrequestheader ("content-type", "application/x-www-form-urlencoded"); xmlhttp.send(thestring);     var wacivar = xmlhttp.responsetext;  wacivar = string(wacivar); wacivar = wacivar.substr(19);  alert(wacivar); } 

you hitting same-origin policy means whilst can make ajax requests domain, cannot read response (that why callbacks not firing). solution here use either cors (adding headers http responses on server side) or jsonp (making custom response jsonp callback). i'd advice use cors provides better error handling, whilst jsonp more of hack.

if want use cors, add described headers in wikipedia article responses must cross-domain.

you asked example of solution, solution must implemented on server side both jsonp , cors.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -