0

In order to control a web service I'm using, I need to send a POST request of the following data. How would I format this into html that sends the POST request when there's a click event or button press?

 <sci_request version="1.0">
  <data_service>
    <targets>
      <device id="00000000-00000000-90A2DAFF-FF050000"/>
    </targets>
    <requests>
      <device_request target_name="myTarget"> 
        my payload string
      </device_request>
   </requests>
  </data_service>

Here's the jquery code I'm trying to execute this from:

$('#button1').click(function(){$.post('--SERVER--', {--THE POST OF INFO FROM ABOVE--});});
nonlinearmind
  • 141
  • 4
  • 13

1 Answers1

0

You can pick an HTML node and get its code as string by using .html() (the parent itself won't be included). Then turn that into an XML document using $.parseXML().

Note that the unclosed node sci_request is problematic and should have a closing element. jQuery will fail to parse to XML if it's missing. You can circumvent the entire issue by parsing a string of the complete XML structure instead of having it in the HTML document for the user.

http://jsfiddle.net/Cn3Pv/

CodeManX
  • 11,159
  • 5
  • 49
  • 70