April 10, 2011

JQuery .post() not working at latest version? SOLVED

Question by Eric T

Something happen with later version of Jquery where it work fine with 1.4.1,1.4.2,1.4.4…
Below is the code that I tried.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" 
    type="text/javascript" charset="utf-8"></script>

Test post.php is a empty file with just opening of <?php ?>

$.post("testpost.php",function(data){
                        alert("Hello World");
                      });

Arghhhh I found the problem that was the button type where it couldn’t be submit so instead of submit I changed to button and finally it works. Thanks everyone for your quick response.

Answer by EmCo

Maybe the alert("Hello world") is not displayed because you are not receiving any response from the server. The function(data){...} is only called on success.

Answer by Starx

First check if testpost.php exists and the path is correct.

On what event is the post request sent? Try wrapping it inside $(document).ready();

$(document).ready(function() {
    $.post("testpost.php",function(data){
         alert("Hello World");
    });
});

Even if this also dont give you a response. Update your question with the code inside testpost.php.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!