javascript - How to get PHP page returned by a jQuery Ajax request -


so have send data php page, , return me php page based on data.

i send data way:

$(document).ready(function() {     $.ajax({         url: '//www.example.com/page.php',         type: "post",         datatype: 'jsonp',         data: { myvar:myvalue },          success: function(response) { console.log("success."); },         error: function(xmlhttprequest, textstatus, errorthrown) { console.log("error."); },         complete: function() { console.log("complete."); }     }); }); 
  • it shows alert saying jquery180014405992737595236_1357861668479 not called (numbers copied other question) think reason it's expecting json result page, when it's not.
  • in chrome says uncaught syntaxerror: unexpected token < referring returned php page, assume code isnt expecting kind of file returned.

to sum up, works, that jquery alert , console error needs fixed, , think right way handling returned result page. hope guys can me fix seems quite simple task, im new this. thanks

removing datatype: 'jsonp' or changing 'json' turns out on script not being executed , getting following error:

  • xmlhttprequest cannot load http://www.example.com/page.php. no 'access-control-allow-origin' header present on requested resource. origin 'http://myserver.com/mypage' therefore not allowed access.

i think reason it's expecting json result page

it's expecting jsonp response. (jsonp not json). said:

datatype: 'jsonp', 

… explicitly forces jquery treat response jsonp (and, side effect, get).

the returned php page, assume code isnt expecting kind of file returned.

the server shouldn't returning php page. should executing php code , returning whatever outputs. looks outputting html.

you need either:

  • not tell script expect jsonp. (note you'll have configure cors on server deal same origin issues) or
  • change php return jsonp

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -