473,385 Members | 1,353 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Returning two request from an ajax call

Claus Mygind
571 512MB
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

✓ answered by johny10151981

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>
>

4 1437
johny10151981
1,059 1GB
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 Expert Mod 8TB
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 1GB
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 Expert Mod 8TB
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
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...
1
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: ...
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:...
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 ...
6
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:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.