I am trying to execute an entire PHP file via the onClick event of some link.
<a onClick="phpSubmit();" class="submitButton">Submit</a>
Makes a successful call to this jQuery function
function phpSubmit()
{
alert('submitting');
$.post("/submit.php");
alert('submitted');
}
Which fails to execute the PHP file "submit.php", in the same directory.
Any ideas?
I have tried $.ajax, $.get and "submit.php" as well as "/submit.php". I don't know why this isn't working, repost $.ajax stuff if you think I was doing something wrong.
EDIT:
It's always the little things, I mistyped a character when I imported the jQuery script which is why $.ajax was undefined.
The above method WORKS.
use
$.post("submit.php");
without a slashRather than use $.post I prefer, and find it much easier for debugging, to use something like:
I would also suggest removing the
/
in front ofsubmit.php
- no need if it's in the same directory.You can get the error message if fail to post the data to PHP file. use $.ajax();