Error(uncaught exception: out of memory) when I do a Ajax Call and Form Post inside JS

Error(uncaught exception: out of memory) when I do a Ajax Call and Form Post inside JS


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 through the Ajax before posting. If I comment out "f.post", 
the ajax runs smoothly otherwise it throws an error:out of memory

Is there a hack or workaround, 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 where I can use event.preventdefault or something. 

please advise. 

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

  1. function SelectQuery(fid) {
  2.    
  3.    var oform = self.parent.document.getElementById("FormList");
  4.    var TType = self.parent.document.getElementById("TicketType")

  5.    for (i = oform.options.length - 1; i >= 0; i--) {
  6.        oform.remove(i);
  7.    }

  8.    var process = "true";
  9.    var sGlobalID = document.getElementById('GlobalID').value;
  10.   
  11.    $.ajax({
  12.        type: "POST",
  13.        url: "Fields.aspx/GetForm",
  14.        data: JSON.stringify({ sGlobalID: sGlobalID, TicketType:2 }),
  15.        contentType: "application/json; charset=utf-8",
  16.        dataType: "json",
  17.        success: function (response) {
  18.            process = "true";
  19.            var forms = response.d;
  20.            $('#output').empty();
  21.            $.each(forms, function (index, form) {
  22.                var opt = document.createElement('option');
  23.                opt.value = form.FormID;
  24.                opt.innerHTML = form.FName;
  25.                oform.appendChild(opt);
  26.            });
  27.        },
  28.        error: function (err) {
  29.            alert("FAIL");
  30.            // alert(err.d);
  31.        },
  32.        failure: function (msg) {
  33.            $('#output').text(msg);
  34.        }
  35.    });

  36.        var GlobalID = document.getElementById('GlobalID').value;
  37.        var f = document.getElementById('FormFields');
  38.        f.action = "Fields.aspx?READQUERY=YES&fid=" + fid + "&sUser=ssy&GlobalID=" + GlobalID;
  39.        f.target = "_self";
  40.        f.submit();
  41.        return (true);
  42.    
  43. }