0

i have a problem with this script in firefox 4. I test the same script in chrome and it works, but in FF the load never stops, maybe some problem with the code

<script type="text/javascript">
    $(document).ready(function(){

        var somevar = 'some info';
        var someothervar = 'some other info';
        var data = "var1=somevar&var2=someothervar";

        $.post("chart.php", data, function(theResponse){
            if (theResponse == 'sim') {
                document.write("test");
            }
            else {
                document.write("testone");
            }
        });
    });
</script>

php file have a simple echo "sim";

thanks

2
  • I'm thinking the problem is in the document.write, which can have some odd and unexpected behaviors. Try replacing it with an alert for testing purposes. Commented Mar 23, 2011 at 18:43
  • Please clarify what "the load never stops" means? Also, why are you using document.write? Commented Mar 23, 2011 at 18:44

1 Answer 1

3

You really can't get away with using "document.write()" for such testing. Change your code like this:

$(document).ready(function(){

    var somevar = 'some info';
    var someothervar = 'some other info';
    var data = "var1=somevar&var2=someothervar";

    $.post("chart.php", data, function(theResponse){
        if (theResponse == 'sim') {
            alert("test");
        }
        else {
            alert("testone");
        }
    });
});

Because the response to the request is very likely to be received after the browser has finished with the original page, the call to "document.write()" will have the effect of obliterating that page.

Beyond that, you can try the TamperData plugin for Firefox (if it's been updated for FF4 ...) to watch the progress of HTTP requests. FireBug will show you XHR requests too.

Sign up to request clarification or add additional context in comments.

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.