• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 318
  • Last Modified:

Generate report xml and download to client

Hi,
Since i am beginner of Jquery, i'd like to ask how i can use Jquery to ask sever generate xml report and download to client:

1- from client i post typeReport, and <key, value> pair to server using $.ajax(...)
2- from server depending on the typeReport, it create xml file and download to client to display.

Could you please help? Thanks,

Regards,
XT
0
mtran888
Asked:
mtran888
  • 3
  • 2
2 Solutions
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
If you are really unsure of this, I would break this out into several separate questions. (Posting data, Receiving and  processing data to create xml, Reading xml )

In short you are going to use jquery ajax to send your data.   Before posting data, you first need to set up your page you are posting data to to receive the data, do any error checking, data scrubbing, validation, processing and output to xml.

Now you can post your data with ajax to somePage.php or asp(x)

$.ajax({
  type: "POST",
  url: "somePage.php",
  data: { name: "John", location: "Boston" }
}).done(function( msg ) {
  alert( "Data Saved: " + msg );
});

Once you get the alert and can see your data, replace the alert line with a more detailed function to read the xml  http://api.jquery.com/jQuery.parseXML/ Parsing your xml takes special set up based on how you have set up y our xml page.  Get the first 2 steps done first, then create a new question on parsing the xml you created.
0
 
mtran888Author Commented:
Hi,

Thanks so much for your advise. Since I am the first time use web app. what do you mean"you first need to set up your page you are posting data to to receive the data"

Thanks again.

XT
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Ajax sends some data to a receiving page that processes the data.  The receiving page would be just as if you were using it to post form data to.

The code below

 $.ajax({
  type: "POST",
  url: "somePage.asp",
  data: { name: "John", location: "Boston" }
}).done(function( msg ) {
  alert( "Data Saved: " + msg );
});

is the same as

<form action="somePage.asp" method="post">
<input type="hidden" name="name" value="john">
<input type="hidden name="location" value="boston">
<button type="submit">Submit</button>
</form>
<%
response.write request.form("name")&" "&request.form("location")
%>

With the main difference ajax code is on page 1, posting to page 2.  Page 2 processes the data and displays it as html, text, json or xml.  Finally page 1 reads the data from page 2 and displays it using, ".done(function( msg ) {" where msg is the output from page 2.

Since you are just starting out, take this one step at a time.  I would first make a page 2 with static data that just outputs some pre made xml, text, json or html.  Then try and use your ajax to call page 2 and display it.  

Once that works, you need to build page 2 to accept data from the ajax call on page 1 and process it and display the output in json, xml, html or text.
0
 
mtran888Author Commented:
Thanks Padas. I really appreciate your explanation.
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Great! Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now