0

I'm trying to call a php function to do some SQL stuff.

I've read on stack that it's possible, but only if I use ajax. So I've tried.

Here is the ajax :

$.ajax({ url: './put_in_table.php',
    type: 'get',
    success: function(output) {
        console.log(output);
    }
});

Unfortunately, It does nothing, and the output returned by the request is containing the PHP source code.

Php code is just a very simple test :

<?php
    echo "lol";
?>

Does anybody have an idea why the php is not executed? (It only contains an echo). Thanks in advance.

7
  • 2
    If it's returning the PHP source code: do you even have a set up PHP server that's serving the file? Commented Sep 14, 2016 at 13:44
  • Yes I do have one Commented Sep 14, 2016 at 13:44
  • So what happens when you open the url directly in the browser? This seems unrelated to ajax... Commented Sep 14, 2016 at 13:45
  • Does it start with <? or <?php Commented Sep 14, 2016 at 13:45
  • If you can please show your PHP code Commented Sep 14, 2016 at 13:45

1 Answer 1

1

If your php code is not parsed but returned, install php on your server

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

10 Comments

I don't know if does matter, but I'm devlopping on a local server using xampp, and there is a PHP server running
sorry for asking, what URL are you browsing to? something like 127.0.0.1/put_in_table.php or localhost/put_in_table.php
I'm using localhost
@souki Can you confirm your put_in_table.php works? In other words: do you see lol echoed on the screen? What happens if you change the AJAX type from GET to POST?
Well, I don't see "lol" echoed on the screen, because the php code is not executed, but it should work I guess, because it contains nothing more than the "echo", which is correct I suppose. It never worked, I've just tried it yesterday
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.