0

I have one quick question for experienced ones.

I have a page that does a jquery ajax post to another php page with javascript in it. My question is, will the javascript get executed as well?

Another question. lets say, that instead of javascript, I have another jquery ajax post request to a third php.

Will any of the 2 work?

3
  • I'm not sure I understand your question. One does not post from one page to another, but from a page to a server. Could you provide some example code? Commented Jul 5, 2013 at 16:07
  • I can't I have not yet. I'm still doing research before I do so to save time.. I'd be wasting time to code and in the end it was never possible.. Thanks though for commenting sir :) Commented Jul 6, 2013 at 1:34
  • I can't. I have not yet* Commented Jul 6, 2013 at 2:55

2 Answers 2

2

Unless the javascript in that "another php page" is actually returned to the client and somehow inserted into the DOM, the JS cannot and will not execute. The resulting output of an AJAX operation is returned as a string to the code that performed the ajax call. It's not interpreted/parsed except in a few very specific cases.

Sign up to request clarification or add additional context in comments.

1 Comment

Sir is there any way to make the javascript at "another php page" run? this is my plan.. an offline php file is ran at a client's computer. Then that php file has jquery post request to my live/online php. The page online will track the location with maxmind's API is this possible? will the API track it?
1

If you're using jQuery's AJAX function to send POST variables to a PHP file, only the backend code will be executed. However, upon success of the AJAX call, you can execute some more JS code as follows

//Define whatever variables you want to pass along to the PHP file
var variable = "";

$.ajax({
    url: "file.php",
    type: "POST",
    data: "variable="+ variable,
    success: function(data) 
    {
        //Upon success of the call, you can execute JS code here
    }
});

Additional info here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.