Is it possible to parse an external php file via XMLHttpResquest? If not, how would I exectute an external php file on a page, or load the script into the document?
You would have to make a CURL request from your PHP to a server which is geared to serve raw PHP code rather than execute it. Normally servers don't print the server-side code so you might have some issue there.
You can then use the eval()
function to execute raw PHP code
http://php.net/manual/en/function.eval.php
Also, I would recommend finding an alternative to whatever it is you are trying to achieve because, unless you know exactly what you are doing... it sounds wrong.
According to same origin policy you cant . XMLHttpResquest can only call scripts from same server.
But there is a hook for this. I dont know how exactly you do this in core javascript, but in jQuery you can do something like this:
var aURL="SOME_EXTERNAL_URL";
$.ajax({
url: aURL+"&callback=?",
data: "message="+commentdata,
type: 'POST',
success: function (resp) {
alert(resp);
},
error: function(e) {
alert('Error: '+e);
}
});