locked
SOAP post: correct data being sent, wrong data being display RRS feed

  • Question

  • User-18738458 posted

    HI,

    I have an HTML And JS that sends a SOAP request (using options selected via the pages dropdown options) and deals with the reply.

    The reply is displayed in Console.log and saved as a txt.

    The initial iteration thought the page sends the correct data from the page and displays the "<g class="gr_ gr_375 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="375" data-gr-id="375">datapacket</g>" in console, and in the <g class="gr_ gr_397 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del" id="397" data-gr-id="397">txt</g> files.

    Subsequent iterations <g class="gr_ gr_436 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" id="436" data-gr-id="436">sends</g> the correct data ( confirmed by using the consoles Network option, locating the POST and looking at the request body), but the Console log (and txt file) ae the previous iterations data. 

    Initial Code

        $('.updatePrices').click(function () {
    
            var Rate = document.getElementById("ID").value;
            var Type = document.getElementById("type").value;
            var beginDate = $('#start').val();
            var endDate = $('#end').val();
            var feature = document.getElementById("feature").value;
            var price = $('#price').val();
            var Plan = $('#plan').val();
    
            var RoomData = '<impl:update> <impl:Rate>' + Rate + '</impl:Rate> <impl:beginDate>' + beginDate + '</impl:beginDate> <impl:endDate>' + endDate + '</impl:endDate> <impl:Type>' + Type + '</impl:Type> <impl:Feature>' + feature + '</impl:Feature> <impl:Code>' + Plan + '</impl:Code> <impl:price>' + price + '</impl:price> </impl:update> ';
    
            dataPacket = dataPacketOpen + updatedataPacket + RoomData;
            dataPacket = dataPacket + updatedataEnd + dataPacketClose;
            console.log(dataPacket);
    
            $.ajax({
                url: wbURL,
                dataType: "xml",
                contentType: "text/xml; charset=\"utf-8\"",
                type: "POST",
                headers: 'OMMITED',
                data: dataPacket,
                success: dealWithResponse,
                error: UpdatePricexmlError
            });
        });

    Response Function (which is where I think the issue is, but I cannot see it )

    	    function dealWithResponse(xml) {
    
            var price = $(xml).find("updateMessage").length;
    
    		if (price >= 1) {
                lookFor = "updateMessage";
                successMessage = "Price Record ";
            }
    
            var xmlDataCount = $(xml).find(lookFor).length;
            var errorcount = 0;
            var recChngCount = 0;
    
            $(xml).find(lookFor).each(function () {
                var xmlerrorCode = $(this).find('error').attr("Code");
                var xmlerrorType = $(this).find('error').attr("Type");
                var xmlerrormsg = $(this).find('error').text();
                var xmlerrortoken = $(this).find('token').text();
                recChngCount = recChngCount + 1;
    
                if ((xmlerrorCode === "") && (xmlerrorType === "")) {
                    console.log("Success: " + successMessage + "update request: " + recChngCount + "\n " + xmlerrormsg + "\n Token = " + xmlerrortoken);
    
                    var file2 = new Blob([successMessage, "\nMessage: " + xmlerrormsg + "\n" + dataPacket], { type: "txt" });
                    if (window.navigator.msSaveOrOpenBlob) // IE10+
                        window.navigator.msSaveOrOpenBlob(file2, "Success-" + xmlerrortoken + ".txt");
                    else { // Others
                        var a2 = document.createElement("a"),
                            url2 = URL.createObjectURL(file2);
                        a2.href = url2;
                        a2.download = success.txt;
                        document.body.appendChild(a2);
                        a2.click();
                        setTimeout(function () {
                            document.body.removeChild(a2);
                            window.URL.revokeObjectURL(url2);
                        }, 0);
                    }
                }
                else {
                    errorcount = errorcount + 1;
                    msg = msg + xmlerrormsg;
                    console.log("ERROR: " + successMessage + "update request: " + recChngCount + "\n Error Code: " + xmlerrorCode + " - Error Type: " + xmlerrorType + " \n " + xmlerrormsg + "\n Token id =" + xmlerrortoken + "\n " + dataPacket +"\n\n");
    
                    ///Save ERROR message to file LOCALLY
                    var file = new Blob(["Error Code: " + xmlerrorCode, "\nError Type: " + xmlerrorType, "\nError Message: " + xmlerrormsg + "\n" + dataPacket], { type: "txt" });
                    if (window.navigator.msSaveOrOpenBlob) // IE10+
                        window.navigator.msSaveOrOpenBlob(file,"ERROR-"+ xmlerrortoken+".txt");
                    else { // Others
                        var a = document.createElement("a"),
                            url = URL.createObjectURL(file);
                        a.href = url;
                        a.download = Error.txt;
                        document.body.appendChild(a);
                        a.click();
                        setTimeout(function () {
                            document.body.removeChild(a);
                            window.URL.revokeObjectURL(url);
                        }, 0);
                    }
                }
            });
        }
    

    The <g class="gr_ gr_709 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="709" data-gr-id="709">dataPacket</g> doesn't get replaced with the newer version, but I cannot see why not

    I have tried adding a datapacket=<g class="gr_ gr_959 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation only-del replaceWithoutSep" id="959" data-gr-id="959">""</g>; line to the beginning, but although the data gets sent out ok (again, checked using the network tab in the console) the txt and console display <g class="gr_ gr_1404 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" id="1404" data-gr-id="1404">are</g> blank.

    Why is it displaying the previous data?

    what can I do to resolve <g class="gr_ gr_1478 gr-alert gr_gramm gr_inline_cards gr_run_anim Style replaceWithoutSep" id="1478" data-gr-id="1478">it ?</g>

    Thanks in advance

    Friday, December 6, 2019 2:44 PM

Answers

  • User-719153870 posted

    Hi G-Oker,

    Subsequent iterations sends the correct data ( confirmed by using the consoles Network option, locating the POST and looking at the request body), but the Console log (and txt file) ae the previous iterations data. 

    We can see no iterations in your code used to change the value of datapacket. I mean it just should be displaying the previous data since it's not changed anywhere in your code.

    The whole process shoul be: click the updatePrices to fire the function -> set value for your dataPacket -> console.log(dataPacket) -> use Ajax and put the dataPacket as the data -> if the behind event completed successfully, fire the success event of your Ajax which is dealWithResponse -> create a txt file.

    The console.log(dataPacket) was fired once and never again in your code, are you talking about that you clicked the updatePrices again? If so, the value of dataPacket is totally based on those several controls' value.

    Not really understand the problem, maybe you could decribe more detailly with more information?

    Best Regard,

    Yang Shen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 9, 2019 7:18 AM

All replies

  • User-719153870 posted

    Hi G-Oker,

    Subsequent iterations sends the correct data ( confirmed by using the consoles Network option, locating the POST and looking at the request body), but the Console log (and txt file) ae the previous iterations data. 

    We can see no iterations in your code used to change the value of datapacket. I mean it just should be displaying the previous data since it's not changed anywhere in your code.

    The whole process shoul be: click the updatePrices to fire the function -> set value for your dataPacket -> console.log(dataPacket) -> use Ajax and put the dataPacket as the data -> if the behind event completed successfully, fire the success event of your Ajax which is dealWithResponse -> create a txt file.

    The console.log(dataPacket) was fired once and never again in your code, are you talking about that you clicked the updatePrices again? If so, the value of dataPacket is totally based on those several controls' value.

    Not really understand the problem, maybe you could decribe more detailly with more information?

    Best Regard,

    Yang Shen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 9, 2019 7:18 AM
  • User-18738458 posted

    You are quite correct. I had not put any iterations/ variable declarations in the deal wit response function.

    thank you  

    Tuesday, December 10, 2019 6:17 PM