2

I am doing a prototype that will fetch a variety of XMLs from a web resource location and then display them on the DOM.

Here is the function

    function readXML()
{
    $.ajax({
        type: "GET",
        url: "https://collaboratewiki.com/wikiattachments/61736956/engineer.xml",
        dataType: "xml",
        success: function(xml) 
        {
            window.alert("success")
        },
        error: function(xhr,err)
        {
            alert("readyState: "+err.readyState+"\nstatus: "+err.status);
            alert("responseText: "+err.responseText);
        }
});


}

When I call this function it goes to the error case but I get "Undefined" in my message output.

enter image description here

I need to find out why I can't fetch my XML but with this output its not helpful at all.

How do I get all the details of the error that is happening with the AJAX call?

I have tried instead of "err.responseText" , "xhr.responseText" but I still get the undefined.

Thanks

2
  • P.s. could it be because its HTTPS? Commented Jan 23, 2013 at 13:43
  • Are you getting any other errors from the console? Commented Jan 23, 2013 at 13:43

2 Answers 2

9

From the documentation:

error

Type: Function( jqXHR jqXHR, String textStatus, String errorThrown )

The second and third arguments are strings, not objects, so they won't have additional properties on them. Some of the ones you're trying to get (such as readyState) will be available from the xhr object in your code, rather than from err (which is just a string).

You may want to try something like this:

error: function(xhr,textStatus,err)
{
    console.log("readyState: " + xhr.readyState);
    console.log("responseText: "+ xhr.responseText);
    console.log("status: " + xhr.status);
    console.log("text status: " + textStatus);
    console.log("error: " + err);
}
Sign up to request clarification or add additional context in comments.

7 Comments

I dont really understand the Jquery documentation , it does not make sense to me. Could you give me code solution please.
@loosebruce Updated with a code snippet (I can't guarantee those properties are available, but I believe they are). You really should learn how to understand the documentation, though, it will answer most questions for you; the key part here is the types of the arguments passed - you were trying to use strings as objects.
Ok I just tried this , the output was : readystate = 0 , responsetext ="" , status = 0 , textstatus = "error" m error = "". What does this mean?
@loosebruce You may be running up against the Same origin policy.
Ok I just tried putting the XML on another resource location and I now get an error : "No Transport"
|
1
                $("#box #tozihat .x1").click(
                function()
                {
                    var id=0
                    var length='';
                    id=$(this).attr('id');
                    length=$("#bordersabad #"+id+"").length;



                    $.ajax({
                        type:'post',
                        url:"sabad.php",
                        data:{idmahsool:id}
                        })
                        .done(function(){

                            if(length==1){
                                var tedad=0;
                                tedad=$("#bordersabad #"+id+"#tedad").html();
                                alert(tedad);
                            }
                            else
                            {
                            }

                        })

                })

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.