locked
Error(uncaught exception: out of memory) when I do a Ajax(JSON) Call and "Javascript" Post RRS feed

  • Question

  • User-1158855013 posted

    I understand there is a solution in jquery to use event.preventdefault but I'm constrained with the limitation I have with the current structure.
    There is an onclick link that calls the "selectQuery" function and then it goes trhough the Ajax before posting. If I comment out "f.post",
    the ajax runs smoothly. Is there a hack or workaround solution, I can use inside SelectQuery method where it will work similar to event.preventdefault.
    I tried return false; that didn't work. I 'm thinking we need to have a separation of duties between ajax call and form submit,
    if I can have an jquery onclick events inside SelectQuery. or something. please advise.

    function SelectQuery(fid) {
    		    
    		    var oform = self.parent.document.getElementById("FormList");
    		    var TType = self.parent.document.getElementById("TicketType")
    
    		    for (i = oform.options.length - 1; i >= 0; i--) {
    		        oform.remove(i);
    		    }
    
    		    var process = "true";
    		    var sGlobalID = document.getElementById('GlobalID').value;
    		   
    		    $.ajax({
    		        type: "POST",
    		        url: "Fields.aspx/GetForm",
    		        data: JSON.stringify({ sGlobalID: sGlobalID, TicketType:2 }),
    		        contentType: "application/json; charset=utf-8",
    		        dataType: "json",
    		        success: function (response) {
    		            process = "true";
    		            var forms = response.d;
    		            $('#output').empty();
    		            $.each(forms, function (index, form) {
    		                var opt = document.createElement('option');
    		                opt.value = form.FormID;
    		                opt.innerHTML = form.FName;
    		                oform.appendChild(opt);
    		            });
    		        },
    		        error: function (err) {
    		            alert("FAIL");
    		            // alert(err.d);
    		        },
    		        failure: function (msg) {
    		            $('#output').text(msg);
    		        }
    		    });
    
    		        var GlobalID = document.getElementById('GlobalID').value;
    		        var f = document.getElementById('FormFields');
    		        f.action = "Fields.aspx?READQUERY=YES&fid=" + fid + "&sUser=ssy&GlobalID=" + GlobalID;
    		        f.target = "_self";
    		        f.submit();
    		        return (true);
    }

    <a href="#" onclick="SelectQuery(2);"><font face="Tahoma" color="#668cd9" size="1"><strong>Query52620161048</strong></font></a>
    (this link is generated in code behind)


    Thursday, May 26, 2016 6:49 PM

Answers

  • User-474980206 posted
    The form submit should cancel the Ajax call. Probably you want to do the form submit after the Ajax completes. Just move the code inside the Ajax success.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 26, 2016 11:27 PM

All replies

  • User-474980206 posted
    The form submit should cancel the Ajax call. Probably you want to do the form submit after the Ajax completes. Just move the code inside the Ajax success.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 26, 2016 11:27 PM
  • User61956409 posted

    Hi shehz81,

    The ajax() method is used to perform an AJAX (asynchronous HTTP) request, you have to prevent the form from submitting before the request finishes. As bruce said, you could modify the code to move form submit code inside AJAX success callback function.

    Best Regards,

    Fei Han

    Monday, May 30, 2016 3:23 AM