Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
ajax using dollar post
Old 02-03-2011, 11:53 PM ajax using dollar post
Ultra Talker

Posts: 254
Trades: 0
i am using ajax using the $.post method my code is

<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
$("#addbutton").ajaxStart(function(){
$("#loading").css("display","block");
});

immediately after $(document).ready(function() {

});

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

$("#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
sudhakararaog is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-04-2011, 04:50 AM Re: ajax using dollar post
phpdasan's Avatar
Experienced Talker

Posts: 37
Name: Karthick B
Trades: 0
hey, why can't you use $.ajax instead of $.post and u can use blockUI plugin for your "processing text".

For $.ajax
http://api.jquery.com/jQuery.ajax/

For blockUI (go for the demos and have a try on it)
http://jquery.malsup.com/block/

One sample shall be like,
HTML Code:
$("#addbutton").click(function(){  

$.blockUI({ message: '<h1><img src="busy.gif" /> Just a moment...</h1>' });

$.ajax({
   type: "POST",
   url: "some.php",
   data: "name=John&location=Boston",
   
   complete: function(){
     $.unblockUI();
   }
   success: function(msg){
     
      alert( "Data Saved: " + msg );
   }
   error:function(XmlHttpRequest,statusText,errorThrown){
     // handle errors here
   } 
 });

 });
__________________
There is no secret ingredient.
phpdasan is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to ajax using dollar post
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.16570 seconds with 12 queries