XML Post with PHP form works, jQuery .ajax does not -


i have simple php form posts xml data url, responds more xml. here is:

form action="[...]" method="post">          <textarea name="xml" rows="30" cols="100">             <rrequest version = '2.13'>                 <request>                     <command>update</command>                     <pd>                         <rid>1</rid>                         <extid>111111111</extid>                     </pd>                 </request>             </rrequest>          </textarea>         <br>         <input value="submit request" type="submit">      </form> 

this works beautifully. attempting implement same thing, using jquery. here code:

        <script>          $(document).ready(function() {              $("#submit").click(function(){                  var xml_data = $("#xml").val();                  $.ajax({                     type: "post",                      url: "[...]",                      data: xml_data,                     contenttype: "text/xml",                     datatype: "text",                     cache: false,                     success: function(data){                         $("#xml").val("");                         $("#xml").val(data);                     },                     error: function(xhr, textstatus, errorthrown){                         alert("it no works");                     }                 });              });          });      </script>  </head>  <body>          <textarea id="xml" rows="30" cols="100">             <rrequest version = '2.13'>                 <request>                     <command>update</command>                     <pd>                         <rid>1</rid>                         <extid>111111111</extid>                     </pd>                 </request>             </rrequest>          </textarea>         <br>         <input type="button" id="submit" /> 

this, however, not work. contact server, server returns bad request message, makes me think data being sent not correct. 2 textareas containing xml identical. appreciated.

i using jquery 2.1.3.

replace line

  var xml_data = $("#xml").val(); 

with

  var xml_data = {xml: $("#xml").val() }; 

upd: these parameters should removed .ajax() request:

  contenttype: "text/xml",   datatype: "text", 

Popular posts from this blog