Z
Z
zayko2011-09-23 15:58:10
JavaScript
zayko, 2011-09-23 15:58:10

jQuery XML generation and sending to server via Ajax?

I would like to send ajax to the xml server, which contains the parameters received from the form.

I do something like this:

function forming_ajax_request(){<br>
    var arg_1 =  $('#form_1_arg_1').val();<br>
    var arg_2 = $('#form_1_arg_2').val();<br>
<br>
    var my_xml = $('<xml />');<br>
    var arg = $('<arg />', {'value': arg_1});<br>
    $(my_xml).append($(arg));<br>
    var arg = $('<arg />', {'value': arg_2});<br>
    $(my_xml).append($(arg));<br>
    <br>
    jQuery.ajax({<br>
      type: "POST",<br>
      url: '#{ajax_url}',<br>
      data: {my_xml: my_xml},<br>
      dataType: "html",<br>
      success: function(data, status, xhr){ alert('Success') },<br>
      beforeSend: function(xhr){ alert('Before') },<br>
      complete: function(xhr, status){ alert('Complite') },<br>
      error: function(xhr, status, error){ alert('Error') }<br>
    });//jQuery.ajax<br>
  }<br>


Advise how to form xml if my approach is not correct.
The problem is that I can't find a way to cast my_xml to a string form, because data: {my_xml: my_xml} doesn't work for the dom object, which is actually obtained.

Thank you!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
O
Oleg Yakovenko, 2011-09-23
@zayko

Ummm, well, if you do xml like this $(my_xml).append($(arg));,
then what prevents you from calling the jquery function .html();for your object?

A
Anatoly, 2011-09-23
@taliban

data: {my_xml: my_xml}
There is a chance, after converting xml to text form, to get an unexpected key =)

M
max_rip, 2011-09-24
@max_rip

It?

Z
zayko, 2011-09-23
@zayko

Thanks everyone. I will try.
There is an objective reason not to use Json - the customer's condition.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question