Multiple AJAX requests at the same time not working

, 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 part of the page) happens before the deletion is executed. The result of this is that when the deletion has been executed, the page is already updated, and the deleted message is still there. The script
What I now have is: function doAjax(url, element_id, img_url) { var ajaxObject = createAjaxObject();'GET', url, true); ajaxObject.onreadystatechange = function() { if(ajaxObject.readyState==4 && ajaxObject.status==200) { document.getElementById(element_id).innerHTML = ajaxObject.responseText; delete ajaxObject; } else { if(img_url) document.getElementById(element_id).innerHTML = ''; } }; ajaxObject.send(); } to execute the actions, and function createAjaxObject() { var ajaxObject; try { ajaxObject = new XMLHttpRequest(); } catch (e) { try { ajaxObject = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { try { ajaxObject = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { return; } } } return ajaxObject; } to create the AJAX object.

Posted On: Sunday 25th of November 2012 09:06:19 PM Total Views:  147
View Complete with Replies

Related Messages:

rotating multiple images in layers   (117 Views)
hi i found this amazing code in css to rotate images. Untitled Document Rotating image Enter the number of degrees (positive or negative) you want to rotate the image: var rotating=document.getElementById('rotating');"200px";"200px";"progid:DXImageTransform.Microsoft.Matrix(M11='1.0', sizingmethod='auto expand')"; var deg2rad = Math.PI * 2 / 360; function rotate(deg) { var rad = deg * deg2rad; var costheta = Math.cos(rad); var sintheta = Math.sin(rad); rotating.filters.item(0).M11 = costheta; rotating.filters.item(0).M12 = -sintheta; rotating.filters.item(0).M21 = sintheta; rotating.filters.item(0).M22 = costheta; } rotate(5); my question is how would i have it rotate a layer, with a picture inside. the only thing is the picture inside changes name. lol
How to prevent function from beeing called multiple?   (113 Views)
I have a function that changes slides, I have created a pause and resume functions for it, but when the user presses resume button multiple times, then multiple instances of the script is beeing run and the images change too fast. I need to prevent this from happening. This is my script in case it might help to make my sentences above to sound less confusing. /*var image1 = new Image(); image1.src="images/4.jpg"; var image2 = new Image(); image2.src = "images/5.jpg"; var i = 2; function change(){ i = ((i
ajax multiple link problem   (130 Views)
Hi . I have a problem with my ajax code. I have n number of links and I want to pass variables to my sort2.php so that I can understand which link to be run. Is there a way to do it My code is as follows. Link 1 Link 2 Link 3 ...Link n first page Please Wait...
Fill in the blank and multiple choice quiz   (256 Views)
I was wondering if someone could help me In my code below what if answers in question 2 were allowed to be in any order Like: hips,body,knees or knees,hips,body and so on. How should I modify my code Anyone please Quiz var answer_list = [ ['False'], ['body,hips,knees'] // Note: No comma after final entry ]; var response = []; function getCheckedValue(radioObj) { if(!radioObj) return ""; var radioLength = radioObj.length; if(radioLength == undefined) if(radioObj.checked) return radioObj.value; else return ""; for(var i = 0; i < radioLength; i++) { if(radioObj[i].checked) { return radioObj[i].value; } } return ""; } function setAnswer(question, answer) { response[question] = answer; } function CheckAnswers() { var correct = 0; var resp, answ; for (var i = 0; i < answer_list.length; i++) { resp = response[i].toString(); resp = resp.toLowerCase(); answ = answer_list[i].toString(); answ = answ.toLowerCase(); //################################################################################################# if (resp == answ) { correct++; if(i==0){ document.forms[0]"url('correct.gif')"; document.forms[0].a1c.value = ""; } else{ document.forms[0]"url('correct.gif')"; document.forms[0].a1d.value = ""; } } else{ if(i==0){ document.forms[0] = "url('incorrect.gif')"; document.forms[0].a1c.value = " ANS: False. Position the head snugly against the top bar of the frame and then bring the foot board to the infant's feet."; } else{ document.forms[0] = "url('incorrect.gif')"; document.forms[0].a1d.value = " ANS: " + answ; } //################################################################################################### } } document.writeln("You got " + correct + " of " + answer_list.length + " questions correct!"); } 1. When measuring height/length of a child who cannot securely stand, place the infant such that his or her feet are flat against the foot board. True False 2. When taking a supine length measurement, straighten the infant's , , and .
Problem with using multiple functions   (88 Views)
I'm kind of new to JavaScript, I know the basic syntax and how it works but I've been hit with this problem that I can't seem to solve... I use the following code to call a file which gets the RSS feed from one site. function showRSS(url) { if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("rssOutput").innerHTML=xmlhttp.responseText; } }"GET","getrss.phpq="+url,true); xmlhttp.send(); } window.onload=showRSS(""); RSS-feed will be listed here... /*the following line isn't in the code but is what I would like to be able to do Another RSS-feed will be listed here... */ However I would like to pass as perimeter two separate urls, (both when the page loads) from which the information should be displayed in a different place on the page, not in the same div as above. I've tried several methods of fixing this which I think are best not to mention since my explanations can get confusing but the main problem I seem to come up with was calling the same function twice, it would only execute the last one even if I did window.onload=rssOutput; rssOutput2; where rssOutput2 was a copy of the original function and many other methods suggested online. If anyone can help me in getting this done then it would be appreciated greatly.
How do i create multiple mouse events?   (179 Views)
This is javascript: function OpenNewWindow(book) { if (book==1) { document.cover.src='images/KanyLogo.jpg' MyWindow ='', 'myAdWin', 'titlebar=0 status=0, toolbar=0, location=0, menubar=0, directories=0, resizable=0, height=50, width=150,left=500, top=400') MyWindow.document.write('10% Discount for Java Demysti ed!') } if (book==2) { document.cover.src='images/KanyLogo.jpg' ; MyWindow ='', 'myAdWin', 'titlebar=0 status=0, toolbar=0, location=0, menubar=0, directories=0, resizable=0, height=50, width=150,left=500, top=400') MyWindow.document.write('10% Discount for Java Demysti ed!') } if (book==3) { document.cover.src='images/KanyLogo.jpg' ; MyWindow ='', 'myAdWin', 'titlebar=0 status=0, toolbar=0, location=0, menubar=0, directories=0, resizable=0, height=50, width=150,left=500, top=400') MyWindow.document.write('10% Discount for Java Demysti ed!') } } This is the body: Gold Subcription" Silver Subscription Bronze Subscription
jQuery - multiple ajax calls on one page.   (178 Views)
I'm new to this forum so sorry if this maybe in the wrong section for some reason. Basically, what I am trying to do is call several ajax requests using jQuery on the same page, i know that all browsers are capable of requesting multiple requests. However in Chrome and Safari my website works fine, but IE, Firefox and Opera all only call the first request then dont call, the second two. I dont know why though of the code for the site is here:
Problem when using multiple JQuery's   (230 Views)
hi.. i had developed ' ' this site using Jquery. when i use the another Jquery it doesn't work.. i am trying to solve this problem but i cant. can anyone solve this problem
Help with multiple select boxes to update price   (111 Views)
Hi all, im looking for some help with some javascript if thats ok. I am building a system for creating a booklet. I want the user to be able to select the quantity of booklets they require. (eg 50, 75, 100, 125) Then also select the number of pages each booklet will require. (eg. 4, 8, 12) both will be select drop down boxes. I would like the price to be calculated based on the selections and displayed on the page. It will be total price not price per booklet. This is how i have built up the prices in php. if($b_maxpages == '4' && $b_quantity == '50') { $amount = "95.00"; } elseif($b_maxpages == '4' && $b_quantity == '75') { $amount = "103.00"; } elseif($b_maxpages == '4' && $b_quantity == '100') { $amount = "115.00"; } elseif($b_maxpages == '4' && $b_quantity == '125') { $amount = "132.00"; } elseif($b_maxpages == '8' && $b_quantity == '50') { $amount = "147.00"; } elseif($b_maxpages == '8' && $b_quantity == '75') { $amount = "171.00"; } elseif($b_maxpages == '8' && $b_quantity == '100') { $amount = "194.00"; } elseif($b_maxpages == '8' && $b_quantity == '125') { $amount = "218.00"; } elseif($b_maxpages == '12' && $b_quantity == '50') { $amount = "190.00"; } elseif($b_maxpages == '12' && $b_quantity == '75') { $amount = "222.00"; } elseif($b_maxpages == '12' && $b_quantity == '100') { $amount = "255.00"; } elseif($b_maxpages == '12' && $b_quantity == '125') { $amount = "288.00"; } I will also need the selected data to be posted once the form is submitted. Cheers vince
Validate a text field for multiple criteria   (95 Views)
! I have a text field where a user can enter either a(n):American zip code (example: "02475") Canadian zip code (example: "A3F 4G6") A "city/state abbreviation" combination (example: "Toronto, ON", or "Las Vegas, NV") For the most part, users don't have much of a problem with the first two criteria, but some people have some trouble with the third, either by entering simply a state ("NB", or "Texas"), a city, or spelling out the state name "Chicago, Illinois". I need to put together some validation that makes sure that: If the entered text is not an american or canadian zip code (IOW, if the entered text contains no numbers at all - in that case, move on to the next validation check) Check to see if the third to last character is non alphanumeric (if they entered the city/state combination correctly, there would be some sort of non-alphanumeric separator between the city and state abbreviation) if the entered text doesn't fit the criteria, return the error. This is what I think I've got for code, but I"m sure the syntax is off. Is there a chance someone could please point me in the right direction
Can't set event listeners to multiple elements of?   (242 Views)
Hi. I'm trying to add event listeners to multiple elements of the same class. The DOM is something like this: .... ....... .......... .... ... [ .... ..... link text ] .... ... [ link text ] .... I want to attach an event listener to each of the element inside elements of class "someclass". Here's what I did for(var i in document.getElementsByClassName('someclass')) { document.getElementsByClassName('someclass')[i].childNodes[1].addEventListener('click', function(){return alert("link clicked");},false); } When I run this (in Firebug) I get this error:TypeError: document.getElementsByClassName('someclass')[i].childNodes is undefined Even though document.getElementsByClassName('someclass')[S].hasChildNodes(); evaluates to true. (S is any integer literal: 0,1,2...upto to the length of the array-1)>>>document.getElementsByClassName('someclass')[2].hasChildNodes(); >>>true Not sure what I'm doing wrong; are there any alternate ways to do this
validating multiple javascript variables   (256 Views)
Still trying to get my head around some simple javascript issues the following works in php but not in javascript can someone point me in the right direction obviously my code is wrong. if((dobyear==false) && (dobmonth==false) && (dobday==true)) { return 'noyearmonth'; }
JavaScript in PHP won't load multiple scripts   (101 Views)
Hi I am working on a website, that has 2 JavaScript elements. I have a post in another thread about loading content into a HTML DIV, I have that partially working. Doesn't work from a link yet. Does work on initial page load. Ok my problem is: I am using two open source JavaScripts imageMenu, and e2_photo_gallery. I can load one or the other just fine but if I try and load them both on the same page parts of each show up but neither function properly. In the imageMenu the images show up and the links work however the JavaScript animation doesn't. e2_photo_gallery loads below it however all styling is broken, and the JavaScript functions won't load. (Basically looks like an un-formatted DIV) The imageMenu is my navigation bar, and the e2_photo_gallery is only on the photo album page, however what I would like to do is get them both working on the same page, then make some switches. I'd like index.php to basically be a container, has the main logo banner, and imageMenu but when you click the link in the imageMenu I would like it to target and load in a DIV.
AJAX PHP multiple dropdown   (106 Views)
Please can someone help with passing of variable for the 3rd menu. The second menu is populating correctly from the first menu. The third menu doesn't work because it is not pulling the cat1 & cat2 values. I suspect it is the "checkNew" function, which I tried (with limited Javascript knowledge) to copy and alter from the "checkSelected" function.
multiple submit buttons need multiple hidden values   (230 Views)
I am setting up a text search with 3 search buttons to allow 3 different searches from the one text box. Each search has different values for the 2 hidden elements. So far I've got the 3 submit buttons working with the below code but I can't figure how to get the hidden values to be inserted. For each of the 3 different submits I need to tell javascript what the 2 hidden values are. Can anyone help me function OnSubmitForm() { if(document.pressed == 'questions') { document.myform.action ="/search.php" } else if(document.pressed == 'rankings') { document.myform.action ="news/search.php"; } else if(document.pressed == 'courses') { document.myform.action ="forum/search.php"; } return true; }
Getting multiple variables from AJAX   (209 Views)
I have used AJAX lots before and I wondered if it was possible to set variables from an AJAX file E.G. an ajax file could set var set1 = 10; var set2 = 55; with both variables coming from an external file called by AJAX Could you tell me the JS side for performing the request and the format of the file that is requested.
Onclick does not work in ie for multiple object   (94 Views)
I have one table which is generated using javascript dynamically. In have write one function which creates table dynamically for IE i have writed mytable.onClick=some_function(); for onclick event it works fine. But when i generate more than one table dynamically using the same function then onclick does not work. If anyone have solution please reply asap. Thanx for spending your precious time.
Calling pages in multiple DIVs   (90 Views)
I have a site which lists the basic information of CDs and allows the user to click a link to see detailed information regarding each CD. I've been doing that for a long time by just putting the detailed information in a DIV and using a script to toggle the visibility of that DIV. Unfortunately, I've reached the point where that bloats the page too much for it to load efficiently. My idea is to use an AJAX call and simply load the detailed information from an external file whenever the user clicks the link. This is basically the code I've tried to use for that, but using it would require me to individually assign an ID to every DIV, which is unreasonable. I've kicked around various ideas--making a similarly-functioning code that applies to classes instead, using a script to apply an ID to an element when it is clicked and then calling the external page into that, etc.--but none of them have worked out. Can anyone give some specific answers to this problem or even help me think of it from a different angle
Need to add multiple measurements virtual earth   (172 Views)
Does anyone know how to add more measurements to this code without continuing to measure the same distance which is what it does. I want to measure the distance between 2 points, then measure the distance between another 2 points keeping each measurement stored as a variable. geocodecalc.js /* ******************************************************** */ /* The code for the GeoCodeCalc class was copied from here: */ /* */ /* ******************************************************** */ var GeoCodeCalc = {}; GeoCodeCalc.EarthRadiusInMiles = 3956.0; GeoCodeCalc.EarthRadiusInKilometers = 2.093E+07; GeoCodeCalc.ToRadian = function(v) { return v * (Math.PI / 180); }; GeoCodeCalc.DiffRadian = function(v1, v2) { return GeoCodeCalc.ToRadian(v2) - GeoCodeCalc.ToRadian(v1); }; GeoCodeCalc.CalcDistance = function(lat1, lng1, lat2, lng2, radius) { return radius * 2 * Math.asin( Math.min(1, Math.sqrt( ( Math.pow(Math.sin((GeoCodeCalc.DiffRadian(lat1, lat2)) / 2.0), 2.0) + Math.cos(GeoCodeCalc.ToRadian(lat1)) * Math.cos(GeoCodeCalc.ToRadian(lat2)) * Math.pow(Math.sin((GeoCodeCalc.DiffRadian(lng1, lng2)) / 2.0), 2.0) ) ) ) ); }; default.htm.js function LoadMap() { // Load the Map map = new VEMap("myMap"); map.LoadMap(); var latLong = new VELatLong(39.882123, -75.513219); // Attach our onclick map event handler map.AttachEvent("onclick", Map_Click); map.SetCenterAndZoom(latLong, 20); map.SetMapStyle("a"); } // The Map onclick event handler function Map_Click(eventArgs) { var clickedLatLong = eventArgs.latlong; if (map.GetMapMode() == VEMapMode.Mode2D) document.getElementById("myMap").style.cursor = 'crosshair'; { // In 2D Mode the eventArgs.latlong property doesn't contain the lat/long point that was clicked. // So we must figure it out using the x and y coordinates of the point on the map that was clicked. clickedLatLong = map.PixelToLatLong(new VEPixel(eventArgs.mapX, eventArgs.mapY)); } // When the user Right-Clicks, Draw the Polygon if (eventArgs.leftMouseButton) { var newShape = null; if (map.GetShapeLayerCount() > 0) { // Get reference to the Default Shape Layer var shapeLayer = map.GetShapeLayerByIndex(0); if (shapeLayer.GetShapeCount() > 0) { // Get points already plotted var points = shapeLayer.GetShapeByIndex(0).GetPoints(); // Add the newly clicked point to the collection of points points[points.length] = clickedLatLong; newShape = new VEShape(VEShapeType.Polyline, points); // Don't show the shapes icon on the map, we only want to see the line newShape.HideIcon(); } } if (newShape == null) { // If this is the first Point plotted, then show it as a Pushpin newShape = new VEShape(VEShapeType.Pushpin, clickedLatLong); } // Clear out the old shape map.DeleteShapes(); // Add our new shape map.AddShape(newShape); CalculateDistance(); } } function CalculateDistance() { var distMessage = document.getElementById("spanDistanceMessage"); var dist = document.getElementById("spanDistance"); var points = new Array(); // Get all the Points being plotted if (map.GetShapeLayerCount() > 0) { var shapeLayer = map.GetShapeLayerByIndex(0); if (shapeLayer.GetShapeCount() > 0) { points = shapeLayer.GetShapeByIndex(0).GetPoints(); } } if (points.length Virual Earth - Calculate Distance UI Example Virual Earth - Calculate Distance UI Example How To: You can scroll/zoom around the Map as normal. Just Right-Click the Map to draw a polyline and measure it's length. Distance: Plot more points to Calculate distance. Units:  Miles  Feet Written by Chris Pietschmann This code was originally posted here:
Play multiple wav files with embed element   (148 Views)
How to play multiple wav files with embed element using javascript and/or DHMTL I have a page with a liink to play and I need to play audio files through javascript and/or DHTML with embed element.