473,657 Members | 2,555 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Returning two request from an ajax call

Claus Mygind
571 Contributor
Is is possible in a php server side app. to both return a success or failure notice to the client app and also send downloaded information to a new client app.

Problem:

1) send an ajax request to the server to get data for a Word doc mail merge letter.

2) Have the server
a) send the data as if a new page is being streamed out and
b) notify the requesting app data has been served

I am so used to handling this via standard request and response method. My question is this, can it be done via an ajax request?

or

Would I have to receive the data back to the calling app and send another request to server which would stream the data back (seems not so useful

or

In this case should I not make it an ajax call?
Jul 24 '11 #1
4 1460
johny10151981
1,059 Top Contributor
This is what i do in some cases
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  $f=getTheFileName();
  3.  if($f==false)
  4.  {
  5.   echo "<message>failed</message>";
  6.  }
  7.  else echo "<message>success</message><filename>".$f."</filename>";
  8. ?>
  9.  
in javascript
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. onAjaxResponse(text)
  3. {
  4.  Res=getValue(text,"message")
  5.  if (Res=="success")
  6.   {
  7.    FileName=getValue(text,"filename")
  8.    document.location=filename
  9.   }
  10. }
  11. </script>
>
Jul 24 '11 #2
Dormilich
8,658 Recognized Expert Moderator Expert
you could also send a 500 HTTP Error back, in case something went wrong on the server (which of course you would have to handle in your AJAX functions). otherwise, what’s the point in sending back a "200 OK" HTTP message (which is the default)?
Jul 25 '11 #3
johny10151981
1,059 Top Contributor
Dormillich,

Thanks for the information, No I never used 500 HTTP error message. In General I dont check for failure. I only check for success, if the success message is missing I took it as a failure. But I will look at 500 HTTP error and how to handle it.

Thanks
Jul 25 '11 #4
Dormilich
8,658 Recognized Expert Moderator Expert
you would handle it like a success message
Expand|Select|Wrap|Line Numbers
  1. if (xmlhttp.status == 500) {
  2.     // execute code in case of server failure
  3. }
Jul 25 '11 #5

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

Similar topics

1
2452
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 redirected? this situation happen when some urls are only accesible when you are logged (i mean you have session) and if you losed session you are usually redirect to other page. But I don't know is it possible to check that my call was redirect....
1
2335
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
2
5219
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 webservice and the webservice returns a Dataset that contains various customer details taken from database. I have tested that the Webservice itself works. But my ajax call is not working. My ajax call is something like :
1
5014
by: Cartoper | last post by:
How does one go about formatting the date/time string correctly to set the If-Modified-Since to the current date/time in an AJAX call? I know I need something like this: request.setRequestHeader('If-Modified-Since','Wed, 05 Apr 2006 00:00:00 GMT'); But I don't know how to actually format the date/time string.
3
2068
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 several Ajax.Request calls to gather data from the server. What I'm having trouble with is getting the data from the Ajax call back to the custom class instance. I basicially want to get a Javascript array from my PHP page and insert that into the...
3
2083
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 to pass the image serialized back to the browser and then displayed? (or something like that?) I know that I do not need to do it this way but I am wondering if its possible.
5
2784
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: (connection.method ? connection.method : 'post'), on404: function(request){ alert("File Not Found Exception Occured "); this.connections.waitPop(); this.isProcessing = false; this.processNext(); }.bind(this),
9
37314
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 2010-08-25(see attached file) to my app. Then I have created an ajax call in the app to my server_side app in which I invoke the JSON.stringify(dataObj). My "dataObj" is an Associative Array. If one of the array element values contains the "&"...
5
8822
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 document.getElementById("results").innerHTML=xmlHttp.responseText; Its showing me content of JSP in which i am refining my list. I am copying down the code for better understanding Result.jsp <div id ="results" style="position: absolute; left:...
6
2362
by: agam | last post by:
Here is my ajax call: new Request.HTML({ url: 'users.html', method: 'get', update: 'go', evalScripts: true, /* !! Why isn't this working!? */ onComplete: function(){console.log('ajax complete!')} }).send()
0
8403
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8316
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
8833
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...
1
8509
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8610
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
7345
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
4168
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2735
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
2
1730
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.