Results 1 to 3 of 3

Thread: ajax using dollar post

  1. #1
    Member sudhakararaog's Avatar
    Join Date
    Sep 2009
    Posts
    224

    Default ajax using dollar post 4 Feb 2011 @ 04.53

    i am using ajax using the $.post method my code is

    HTML Code:
    <script type="text/javascript">
    $(document).ready(function() {
    
    	$("#addbutton").click(function(){  
    	$.post('task-usingdollarpost.php', {
    			taskname: $("#taskname").val()
    			taskname: $("#taskname").val(),
    			taskname: $("#taskname").val()
    						},  
    			function(response){
    			$("#loading").hide();
    			$("#done").fadeIn(1000).text(response);
    					} 
    	  ); 
    	  return false;
    
    	}); 
    
    });
    
    </script>
    
    html code
    
    <form>
    <input type="text" name="taskname" id="taskname" size="20" />
    <input type="button" name="addbutton" id="addbutton" value="Add"  />
    </form>

    my question is using this $.post method i am able to specify the url, variables that i am passing to a php file and a function that will be called when ajax is complete however what i need is function when the ajax is being processed so that i can show a loading image and error if an error occurs

    for loading i have used this code
    Code:
    $("#addbutton").ajaxStart(function(){ 
    		$("#loading").css("display","block");
    	});
    immediately after $(document).ready(function() {

    });

    and for error i have used this code after the ajaxStart function

    Code:
    $("#addbutton").ajaxError(function(){ 		
            $("#error").css("display","block");
    	});
    is this the right way to show the loading div which has the loading image while the ajax request is being processed when using $.post

    also the ajaxError is not working properly for example if i were to rename the php file in the server that i have mentioned in $.post or if i have a syntax error in the php file then the ajaxError function should be executed however i am getting a browser error message and the error div is not being displayed which i have created to show when an error occurs with $("#error").css("display","block");

    how to fix the ajaxError function
    Last edited by CloudedVision; 6 Feb 2011 at @ 02.14.
      Reply With Quote

  2. #2
    Member janvt's Avatar
    Join Date
    Jan 2011
    Posts
    182

    Default 4 Feb 2011 @ 08.36

    I'm not sure if you can bind .ajaxStart & .ajaxError to the same element. Have a look at the jQuery documentation, they have a good example: .ajaxError() – jQuery API
      Reply With Quote

  3. #3
    Senior Member CloudedVision's Avatar
    Join Date
    Jan 2009
    Posts
    824
    Blog Entries
    4

    Default 6 Feb 2011 @ 02.14

    I'd like to remind you to wrap your code in [code] tags when posting. Also, this question relates to Javascript, not PHP, so I've moved it to the appropriate forum.
      Reply With Quote

Similar Threads

  1. ajax using dollar post
    By sudhakararaog in forum PHP, ASP & Java
    Replies: 2
    Last Post: 6 Feb 2011, @ 02.14
  2. php and ajax
    By sudhakararaog in forum PHP, ASP & Java
    Replies: 0
    Last Post: 18 Jan 2011, @ 04.45
  3. jquery treeview in ajax
    By Snidefeld in forum Javascript Libraries
    Replies: 11
    Last Post: 30 Nov 2010, @ 08.41
  4. loading js files in an ajax script
    By stu2000 in forum Javascript Libraries
    Replies: 11
    Last Post: 4 May 2010, @ 12.45
  5. ASP Ajax Frameworks
    By magicben in forum PHP, ASP & Java
    Replies: 2
    Last Post: 4 Mar 2009, @ 13.55

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •