Sunday, 7 June 2015

All Ajax Methods Example

* Instead of  Ram.txt file use your own text file , Write any Data

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
//These states for Loading files/images only
    $(document).ajaxError(function(){
           //If fail is not loading , this method will work
            alert("Error occured");
        });
    $(document).ajaxStart(function(){
            //At the time of ajax starting
            alert("Started");
        });
    $(document).ajaxStop(function(){
           at the time of ajax ending
            alert("Stopped");
        });
    $(document).ajaxSend(function(){
           //After ajax request start , request will go to server
            alert("Sended");
        });
    $(document).ajaxComplete(function(){
            //If The Ajax Request is success/failure , always it will work
            alert("Ajax Completed");
        });
    $(document).ajaxSuccess(function(){
           //For success only
            alert("Ajax Success");
        });
        $("button").click(function(){
            $(".main").load("Ram.txt");
        });
        $("#pid1").click(function(){
            $("#pid1").load("Ram.txt");
        });
        $(".pid2").click(function(){
            $(".pid2").load("Ram.txt");
        });
});
</script>
</head>
<body>
<div class="main">
<button>Get External Data</button>
<p id="pid1">Paragraph 1</p>
<p class="pid2">Paragraph 2</p>
</div>
</body>
</html>

No comments:

Post a Comment