from.. 2011-03-23 18:40 采纳率: 100%
浏览 37

问题-Ajax jQuery

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

  • 写回答

1条回答 默认 最新

  • weixin_33717298 2011-03-23 18:43
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!