Using Javascript to POST xml to api

I'm trying to post XML data and then do a redirect to the current page, but I can't seem to get it to work.

When I do this:

<form action="" method="post">

it works and posts the data to the website that I want it to.

However, it leads the user to an XML page so I want to post it and then have it redirect to my current contact form page and have a success message of some kind.

I've tried using:

  function loadXMLDoc()
  var xmlhttp;
  if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    if (xmlhttp.readyState==4 && xmlhttp.status==200)

I don't get any errors in my console, but it does not post to the the freshdesk website like I want it to. Does anyone know what I'm doing wrong?



This is an example on how to post with jQuery:

var data = 
    '<helpdesk_ticket>' +
    '<description>This is a test</description>' +
    '<email>[email protected]</email>' + 
$.support.cors = true;
    url: '',
    type: 'POST',
    crossDomain: true,
    data: data,
    dataType: 'text',
    username: 'username1',
    password: 'password1',
    success: function (result) {
    error: function (jqXHR, tranStatus, errorThrown) {
            'Status: ' + jqXHR.status + ' ' + jqXHR.statusText + '. ' +
            'Response: ' + jqXHR.responseText

As you tagged jQuery, here's a jQuery solution which should work (I did not test it):

$.post("", {
   // any parameters here 
}, function(data) {

You still have to specify the parameters, but as you did not provide your form html, I left it empty. Also have a look at the api:


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.