Skip to content
Advertisement

Ajax gets as result whole page from php

I am trying to call php function using ajax. Ajax is called from php with onclick function in button. But instead of value, that the called function add_player returns, i get whole page exec.php. Thank you for your help.

index.php

JavaScript

javascript

JavaScript

exec.php

JavaScript

Advertisement

Answer

I assume that somewhere, but not shown, index.php has …

JavaScript

… surrounding the echo statements. If not, make it so.

If you are returning the entire code of exec.php as your result, that suggests that you do not have your code enclosed within <?php ... ?> tags. That is problem number one. The second problem is how you are retrieving the actual parameters passed to the script. The third problem is how you are trying to send back the results.

exec.php

JavaScript

The final ?> may be omitted. You can also test whether the expected parameters have been passed with:

JavaScript

Ultimately it is what your script writes out that is considered the “return value” for the Ajax request. The PHP interpreter outputs whatever is not within <?php ... ?> tags so when you omitted those tags, your source program itself was written out (with a default mime-type) and considered the return value.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement