473,609 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I show spinners during different Ajax requests?

28 New Member
I want to show spinners when making different Ajax calls.Now, I can show a spinner under a combobox, but I want also to show one more spinner(it can have the same properties with the other spinner) in another part of the html page.For example I have:
Expand|Select|Wrap|Line Numbers
  1. Stations
  2.    <select name="selectStation" id="selectStation" onchange="sta_callStation(this);">  
  3.      </select>
  4.  
  5.         <div id="noOfPassengers"></div>
  6.  
  7.         <div id="sta_numberOfIcons"></div>
  8.  
  9.         <div id="spinner">
  10.         <img src="ajax-loader.gif" alt="Loading..." />
  11.       </div>
Javascript side:
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. $('#spinner').ajaxStart(function () {
  3.     $(this).fadeIn('fast');
  4.     //Set time interval
  5. }).ajaxStop(function () {
  6.     $(this).stop().fadeOut('fast');
  7. });
  8.  //There are lots of functions here
  9. </script>
There are more than one Ajax calls in my script.For example, when the user selects a station from combobox sta_callStation () is called and there is $.getJSON in it.The spinner is shown when the user clicks a station from the combobox.But because there are also another Ajax calls, when I call the other Ajaxs, the spinner below the combobox is also start to spin.I want to create another spinner under the related div.How can I seperate spinners?How can I do that?Thanks for any reply.
Apr 22 '13 #1
2 3318
omerbutt
638 Contributor
Hi notofound,
you might try too use the parameter of the ajaxstart function like this
Expand|Select|Wrap|Line Numbers
  1. $(document).ajaxStart(function(a) {
  2.     alert(a.toSource());
  3.  
you will have the output like object [Object] if you alert a without converting it to source , and once you do you will have to look into the ource text of the object like the following
Expand|Select|Wrap|Line Numbers
  1. ({type:"ajaxStart", timeStamp:1366800488561, jQuery18306740114199208432:true, isTrigger:true, exclusive:(void 0), namespace:"", namespace_re:null, result:(void 0), target:({}), delegateTarget:({}), currentTarget:({}), data:(void 0), handleObj:{type:"ajaxStart", origType:"ajaxStart", data:(void 0), handler:(function (a,b,c) {
  2.     alert(a.toSource());
  3.  
  4.     $( ".log" ).text( "Triggered ajaxStart handler." );
  5. }), guid:2, selector:(void 0), needsContext:(void 0), namespace:""}})
  6.  
it would have something appended to it for every unique call that you could use to spin only the relevant areas
regards,
Omer ASlam
Apr 24 '13 #2
omerbutt
638 Contributor
You can bind the ajaxStart and ajaxStop using custom namespace:
Expand|Select|Wrap|Line Numbers
  1. $(document).bind("ajaxStart.mine", function() {
  2.     $('#ajaxProgress').show();
  3. });
  4.  
  5. $(document).bind("ajaxStop.mine", function() {
  6.     $('#ajaxProgress').hide();
  7. });
  8.  
Then, in other parts of the site you'll be temporarily unbinding them before your .json calls:
Expand|Select|Wrap|Line Numbers
  1. $(document).unbind(".mine");
  2.  
Got the idea from here while searching for an answer.
Apr 24 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
3607
by: tlyczko | last post by:
Hello, I've searched on toggling divs and didn't really find what I was looking for, I saved a bunch of different threads. I have a form with several different text boxes for things like dates, numbers, etc. arranged in a table, each row has the same kind of text boxes for data entry (10 rows probably). I want to have a separate section above the form where I can toggle a div containing an appropriate error message to appear after the...
1
2331
by: Chaprasi | last post by:
Hi, I was wondering how I can achieve to display a 'Please wait loading...' message only if the ajax call is taking more than a second. The message should only appear if the Ajax call is taking more time than a second. In my example I set my ajax timeout for 10 seconds and at my server I sleep for 5 seconds. So in my example
9
5471
by: Jordan Pittman | last post by:
ok i want to wait an x amout of seconds before my ajax script writes the results to a div, but i want it to still display the loading bar, i do have a variable http_rste that holds the readyState and the if statements check that instead just incase i have a need to have the thing stay there an x amount of seconds but i could never get the script right
4
2282
by: =?Utf-8?B?U3JpZGhhcg==?= | last post by:
Hi, Is it possible to Hide/Show controls during a callback? I have a radio button list that does the callback. When it does the callback I need to refresh the grid to reflect the selected value in the radio button. Also I need to hide some check boxes based on the selected value. The checkboxes and radiobuttons are both server controls. Please let me know. Thanks,
1
2667
by: vanirani | last post by:
Hi, Is it possible to send Ajax requests to server other than web server? If so can the requests be sent to a machine running tcp server (in any language) in other system? Where (or which function is used) to mention the server ip and port?
1
2663
by: =?Utf-8?B?TWFuaXNoIEJhZm5h?= | last post by:
Hi, I have tried hard but not able to show waitcursor in betwen different processes.I launch new application from current application by using system.diagnostics.proceesstartinfo.Till second application is fully launched,i want to show waitcursor.I have used Current.Cursor = Cursors.Waitcursor.But it is not working. Any ideas/insights would be highly appreciated. Thanks in advance for repyling(as always) Thanks and Regards.
1
1564
by: DotNetNewbie | last post by:
Hi, I am implement ajax in a web application, and I want to avoid having to go through the entire asp.net page lifecycle since I will be simply return back html/xml, and I have no need of the .net page lifecycle events. What do you suggest is the best way of doing this? I am thinking I could put all ajax related code in a seperate folder
1
2156
by: sarahaziz | last post by:
Hello guys I cerated this chat system with several ajax requests(using jquery).Now i have several ajax requests on a page, it works fine with safari but on firefox it causes a problem of slowness that sometimes when i write a message some letters are missing. This could be the problem of function, browser or network?
4
4272
by: Stephan Needank | last post by:
Hello, I'm encountering an AJAX problem when I try to execute multiple AJAX requests at the same time. What I want to do is delete a message and display the status (succes or failure) of that in div1, and refresh the messages on the page in div2. This needs (for as far as my knowledge reaches) two AJAX actions from which I both need the responseText. The problem What happens when I execute my script is that the second action (refresh a...
0
8074
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8571
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8404
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6997
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5509
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4080
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2530
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1386
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.