Very strange jQuery / AJAX behavior

Posted by Dr. DOT on Stack Overflow See other posts from Stack Overflow or by Dr. DOT
Published on 2012-04-07T17:24:04Z Indexed on 2012/04/07 17:29 UTC
Read the original article Hit count: 438

Filed under:
|
|
|

I have an Ajax call to the server that only works when I pass an alert(); to it. Cannot figure out what is wrong. Can anyone help?

This Does Not Work (ie., Ajax call to server does not get made):

<!--

jQuery.support.cors = true; // needed for ajax to work in certain older browsers and versions

$('input[name="status"]').on("change", function() {

    if ($('input:radio[name="status"]:checked').val() == 'Y') {

        $.ajax({
            url: 'http://mydomain.com/dir/myPHPscript.php?param=' + $('#param').val() + '&id=' + ( $('#id').val() * 1 ) + '&mode=' + $('#mode').val()
        });

    }

    window.parent.closePP();

    window.top.location.href = $('#redirect').val();    // reloads page

});

//-->

This Works! (ie., Ajax call to server gets made when I have the alert() present):

<!--

jQuery.support.cors = true; // needed for ajax to work in certain older browsers and versions

$('input[name="status"]').on("change", function() {

    if ($('input:radio[name="status"]:checked').val() == 'Y') {

        $.ajax({
            url: 'http://mydomain.com/dir/myPHPscript.php?param=' + $('#param').val() + '&id=' + ( $('#id').val() * 1 ) + '&mode=' + $('#mode').val()
        });

        **alert('this makes it work');**

    }

    window.parent.closePP();

    window.top.location.href = $('#redirect').val();    // reloads page

});

//-->

Thanks.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery