2

Ok here's what happens.

I have a form, I fill it out with details, I then press submit, and it will post to another site (their server) and on that page it will return an XML document. The URL is always the same on the result end.

Now, with the XML that was generated I need to get it and put it into a HTML form on the original site.

Ideally, I want to press submit, not be redirected to this site where the output is, and have the output be automatically parsed into a new HTML form. I have tried looking at xmlHTTP requests and can't get my heard around it...

Ok here is the form post bit:

<form target="_blank" action="www.websiteipostto.com" method="POST">

I then arrive at www.websiteipostto.com with the XML document there. I will greatly appreciate any help.

Regards

JEV
  • 2,494
  • 4
  • 33
  • 47

2 Answers2

0

If you want to do everything on clientside, this will help:

http://api.jquery.com/jQuery.post/ for sending request

http://api.jquery.com/serialize/ for prepraing it

you would need to parse xml from response: XML parsing of a variable string in JavaScript

Community
  • 1
  • 1
  • Ok will look at this when I get back, so I can post my form using jquery.post have the results in a div, and then serialise that div ? I skim read it.. – JEV Feb 22 '12 at 13:59
  • however, I would rather move the work for making a request to www.websiteipostto.com and forming a desured form to some serverside script – user1225939 Feb 22 '12 at 14:25
  • Dude, I can get it to like post and serialise but I get no result, or even see any evidence of the XML form. Like it doesn't generate a new form. – JEV Feb 22 '12 at 15:42
0

When you press the submit, you want to:

  1. Don't want to be redirected to this site
  2. Use the XML data to create a new form

The first one could be handled by return false on the submit event. It will cancel the default 'redirecting' action.

The second one needs some parsing with XML.

You could fill in the blank with your specific need for this XML data. More information about how jQuery handle XML data could be found here

// You bind event handler to the form submit 
$('form#name').submit(function () {
  $.ajax({
    type: "POST",
    url: "www.websiteipostto.com",
    success: function (data) {
      $.parseXML(data)
      //There you perform you action on the XML-format data.    
    }
  });

  //Cancel the default redirecting action

  return false;

});
steveyang
  • 9,178
  • 8
  • 54
  • 80
  • Dude awesome answer, So this gets the submit and places it in a new window, but I don't get any new information, can you not assist in helping me parse the XML it's so much easier having some one explain it. – JEV Feb 22 '12 at 15:28
  • Jon. The parsing is a quite specific need which both depends the XML content and what you want to retrieve from it. You could find a tutorial [here](http://think2loud.com/224-reading-xml-with-jquery/). I suggest you open another question for it and paste your XML data and state what you want to archive. – steveyang Feb 23 '12 at 05:19
  • Hi @Jon, You might tick the answer and close this question and tag it for others who has the similar questions :) – steveyang Feb 23 '12 at 17:23