Using Javascript to POST xml to api

后端 未结 2 1511

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:

相关标签:
2条回答
  • 2021-01-21 19:32

    This is an example on how to post with jQuery:

    var data = 
        '<helpdesk_ticket>' +
        '<description>This is a test</description>' +
        '<email>sample@example.com</email>' + 
        '</helpdesk_ticket>'
    $.support.cors = true;
    $.ajax({
        url: 'http://onehouse.freshdesk.com/helpdesk/tickets.xml',
        type: 'POST',
        crossDomain: true,
        data: data,
        dataType: 'text',
        username: 'username1',
        password: 'password1',
        success: function (result) {
            alert(result);
        },
        error: function (jqXHR, tranStatus, errorThrown) {
            alert(
                'Status: ' + jqXHR.status + ' ' + jqXHR.statusText + '. ' +
                'Response: ' + jqXHR.responseText
            );
        }
    });
    
    0 讨论(0)
  • 2021-01-21 19:32

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

    $.post("http://onehouse.freshdesk.com/helpdesk/tickets.xml", {
       // any parameters here 
    }, function(data) {
          document.getElementById("myDiv").innerHTML=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: jQuery.post

    0 讨论(0)
提交回复
热议问题