Question

Each of my calls to an ashx handler is causing me to get the "no element found" error in Firefox but my website does not crash when performing calls to that handler. I also get a "HierarchyRequestError:Node cannot be inserted at the specified point in the hierarchy". Below is the code that is giving me those two errors:

 $.post("checkout_model.ashx?a=CheckSession", function (data) {
                    // if session is still available
                    alert(data);
                    if ($.trim(data).length > 0) {
                        $.post("checkout_model.ashx?a=SaveAddress", $("#addressdetails").serialize(), function (data) {
                            $("#addressresult p.result").remove();
                            $("#addressresult").prepend(data);
                        });
                        storeCookies();
                        // update orderdetails
                        $.post("checkout_model.ashx?a=GetCartContent", function (data) {
                            $("#orderdetails").html(data);
                        });
                        var address = $("#AddressLine1").val();
                        if ($("#AddressLine2").val() != "") address += ", " + $("#AddressLine2").val();
                        address += ", " + $("#Suburb").val();
                        $("#tabaddress").text("Step 1: Modify Address: " + address);
                        $("#accordion").accordion("option", "active", 1);
                        $("#tabaddress").addClass("modifyaddress");
                        $("#tabpayment").removeClass("disabled"); // enable step 3
                    } else {
                        $("#addressdetails").html("<p class='error'>Your order has timed out. You will need to <a href='viewcart.aspx'>select the items</a> to purchase again.</p>")
                    }
                });
Was it helpful?

Solution

If your ajax response includes a "Content-Type" header with the value "text/xml", Firefox expects the response to be valid XML with a single root element. If it is not, Firefox issues the "no element found" error.

As for the second error, it may be that in either of the following lines the value of "data" is not valid HTML or contains tags like <html> or <body>:

$("#addressresult").prepend(data);

$("#orderdetails").html(data);

OTHER TIPS

Add the responseType request.

var xhr = new XMLHttpRequest();
xhr.open('POST', '...', true);
xhr.responseType = 'json';

See this for more details: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top