Question

So I've been trying to debug my jQuery.post() call, and have been getting some weird responses. I'm stuck on what to do next, if anyone had any suggestions, I'd really appreciate it.

<script type="text/javascript">
var debugresp;
var debugpost;
$("#scan .scanSide button.startScan").click(function() {
    // ...
    console.log("Scanning...");
    debugpost = $.post(
        "scan/scan.php",
        {
            "side": side
        },
        function(response) {
            console.log(response);
            /*...*/
        },
        "xml"
    );
    console.log("Sent data...");
});
<script>

The two console.log() calls outside the $.post work fine, the page returns 200 OK with valid data under the Network tab (Debug tools/Chrome), but the internal console.log(response) never fires.

If you noticed, I saved the return from $.post.

// JavaScript console, while page hasn't returned yet
debugpost.state()
// > "pending"
// After the page returns, and console.log(response) hasn't been called
debugpost.state()
// > "rejected"

I've never tried to deal with problems in jQuery.post, but I wouldn't expect "rejected" from the jqXHR that is returned from $.post.

Might anyone have more debugging suggestions or suggestions on how to approach this?

Resources:
jqXHR jQuery.post(...)

Was it helpful?

Solution

Problem solved: I had invalid XML that I was trying to parse.

For anyone else reading this, try jqXHR's fail(function(jqXHR, textStatus, errorThrown) to debug.

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