473,466 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Ajax call and Browser redirect issue

4 New Member
Hi All,

I have a requirement where I need to fire an ajax call(dojo xhrPost)on click of an anchor, but as soon as I click the anchor link browser starts to redirect but ajax call is not finished yet, so I always got bad http return code 0 from the server. I can see in the firebug/developer tool.
Is there any way to stop browser redirect until the ajax call finished or returned a proper response like 200.

here is the code in dojo

Expand|Select|Wrap|Line Numbers
  1. function submitForm{
  2.  dojo.xhrPost({
  3.  url: some url,
  4.  form : someform,
  5.  
  6.  load(function(response, ioArgs){
  7.   //some stuff
  8.  }),
  9.  error(function(response, ioArgs){
  10.   //some stuff
  11.  })
  12.  
  13.  
  14.  });
  15. }
  16.  
I am calling this on click of the anchor tag but browser navigates before the ajax return some proper response.

pls suggest any solution for this.

thanks,
Rakesh
Jan 7 '12 #1
6 5088
Dormilich
8,658 Recognized Expert Moderator Expert
the simple solution is: don’t trigger it with the href attribute. if there is no href, the link can’t load a new page.
Jan 7 '12 #2
rakesh2k78
4 New Member
Thanks Dormilich, but I need to navigate as well, basically I want that AJAX call finished first and then only browser navigate to some x page.Can you pls help with this scenario?
Jan 8 '12 #3
Dormilich
8,658 Recognized Expert Moderator Expert
make it a synchronous call. but if you leave the page anyways, what good does the AJAX call do?
Jan 8 '12 #4
rakesh2k78
4 New Member
Hi Dormilich, thanks for the reply.

Actually, I am submitting a form, but there is situation where user either click on submit button or navigate from navigation bar(anchor tags in terms of menus) and there is no validation on form but we still need to submit default selections. We are using Java Page flow(Apache beehive) controller for form submission and one action is called for normal form submission on click of submit button but on click of navigation there is a different Controller's action is invoked which is taking the user to some screen, that's why I am submitting the form in an asynchronous way. Even though call is made asynchronously and form's values are saved in DB but the response from the server(bad http code 0) and not 200 which is problematic for us and even this call is not happen on all browser, it fails on Safari(Windows XP). Can you pls help with this?
Jan 8 '12 #5
rakesh2k78
4 New Member
Hi All, I solved this issue.

here is the solution :

I returned false on click of anchor and then in dojo.XhrPost i did something like this

load(function(response, ioArgs){
window.location.href = navUrl;
}),

where navUrl is the url of the anchor where we need to navigate.
Jan 10 '12 #6
sai163
1 New Member
Hello,

Can you elaborate a bit more on how you solved this?
I am facing the same issue.
Using dojo.xhrpost. Form values are getting saved, but i getting no response. xhr.status code is "0". It works fine in my localhost, but when i pushed the code on server i am getting no response, though data is getting saved and redirection is successful. Can you tell me why the status code is set to '0'.

@rakesh2k78
Mar 21 '13 #7

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

Similar topics

1
by: Grzegorz Smith | last post by:
Hi everyone. Does anyone know is it possible to check if ajax call was redirect? i mean I connect by Ajax to one URL but I'm redirected to other url. Is there a way to check that my request was...
1
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...
2
by: Zeba | last post by:
Hi guys! I'm new to JS / Ajax; I've been trying to do an Ajax call to my Webservice ( I'm using C# for code-behind). I'm not using any of the libraries available. I am sending my CustID to the...
2
dmjpro
by: dmjpro | last post by:
Is it possible to make AJAX call in the address bar of any WEB-Browser? If possible then please help me to do it. I tried but I failed. And if not then please mention the reason behind it. Ok....
3
by: wendallsan | last post by:
Hi All, I've stumped myself writing an app that uses Prototype and a bit of PHP. Here is what I have: I have a custom class named Default_county_init_data that, upon initialization makes...
3
by: KDawg44 | last post by:
Hi, I would like a verification image for new sign ups on a website. Is there a way to call the PHP script through an AJAX call and have the image passed back and then display? Is there a way...
5
RamananKalirajan
by: RamananKalirajan | last post by:
Hi guys, I am having a problem in Prototypejs AJAX, I am triggering the AJAX call and in the option i am using like the folowing code: new Ajax.Request(connection.url, { method:...
3
by: rbansalit | last post by:
Hi all I am making a very simple ajax call. But I am not getting any message from sever. <html> <body> <script type="text/javascript"> function ajaxFunction()
9
Claus Mygind
by: Claus Mygind | last post by:
I am having trouble escaping the & in a JSON.stringfy() ajax call. I don't even know if I am stating the problem correctly here. In my app I have linked json2.js from http://www.JSON.org/json2.js...
5
by: samarinder | last post by:
I am displaying the results by iterating the list in div tag say "results" in my case.For refining of search i am using ajax call. But when i am getting response back from this below snippet ...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
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 ...

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.