www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Get response text from Ajax() when sending XML

Hybrid View

  1. #1
    Join Date
    Dec 2008
    Posts
    488

    resolved [RESOLVED] Get response text from Ajax() when sending XML

    I'm using jQuery.ajax() to send XML to my sever to be saved. I'm not sure how to deal with response text in this scenario. I want to send the XML file to page.php, then have it echo back with success or failure of saving the file. I the need to get that response text and check it in my JS.

    Code:
    $.ajax({
        url: "page.php"
        , type: "POST"
        , contentType: "text/XML"
        , processData: false
        , data: inputXML
        , success: function(event, request, options) {
            //read response text and send it to function saveComp()
        })
        , failure: ajaxError
    });
    as you can see I don't know where to go in my success function to get the page.php responseText.

  2. #2
    Join Date
    Dec 2008
    Posts
    488
    Nevermind, I figured it out. The server response is already sent back as the first argument in the success function. Since it's pure text, I simply eval it as JSON object

    Code:
    $.ajax({
        url: "page.php"
        , type: "POST"
        , contentType: "text/XML"
        , processData: false
        , data: inputXML
        , success: function(data) {
            var servResp = eval(data);
            if (!servResp.success) {
                alert("Error saving file: " + servResp.msg);
            }
            else {
                showXML();
            }
        })
        , failure: ajaxError
    });

  3. #3
    Join Date
    Sep 2012
    Posts
    1
    This way of Posting Xml doc is not working. I tried storing an xml doc in the inputXML passed .Below is my code
    function createXMLDocument(s) {
    var xmlDoc;
    if (window.DOMParser) {
    var parser = new DOMParser();
    xmlDoc = parser.parseFromString(s, 'text/xml');
    } else {
    xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
    xmlDoc.async = 'false';
    xmlDoc.loadXML(s);
    }
    return xmlDoc;
    }

    var xmlString = createXMLDocument(xmlData);
    $.ajax({ async: 'false',
    cache: 'false',
    contentType: 'text/xml',
    data: createXMLDocument(xmlString),
    datatype: 'json',
    processData: false,
    type: 'POST',
    url: 'ws/default.aspx',
    success: AjaxSucceeded,
    error: function (msg) {
    debugger;
    alert(msg);
    }
    });

    When I try to retrieve this in HttpContext.Current.Request, I'm not able to retrieve the requeste xml.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles