浏览器不停止加载与jQuery $不用彷徨 [英] Browser doesn't stop loading with jQuery $.get

查看:112
本文介绍了浏览器不停止加载与jQuery $不用彷徨的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的jQuery(1.4)code测试的cookies是否被接受:

I use the following jQuery (1.4) code to test whether cookies are accepted:

$.get("http://localhost:8080/cookietester/cookietester", function(data) {
    if (data == "false")
        document.write("Activate cookies!");
    else if(data == "true")
        document.write("ok");
});

不过,浏览器发出信号,它不会停止页面加载。谷歌浏览器5不执行该脚本正常,不显示任何内容。

But the browser signals that it doesn't stop page loading. Google Chrome 5 doesn't execute the script properly and doesn't display anything.

有什么问题与此code?

Is something wrong with this code?

推荐答案

您不能使用 < $ C C> $文件撰写 在那种情况下(其实我避免它只要有可能),而使用的 .append() 将消息添加到&LT;身体GT; ,像这样的:

You can't use document.write in that scenario (actually I avoid it whenever possible), instead use .append() to add a message to the <body>, like this:

$.get("http://localhost:8080/cookietester/cookietester", function(data) {
  if (data == "false")
    $(document.body).append("Activate cookies!");
  else if(data == "true")
    $(document.body).append("ok");
});

或者,你可以只是提醒它:

Or, you could just alert it:

$.get("http://localhost:8080/cookietester/cookietester", function(data) {
  if (data == "false")
    alert("Activate cookies!");
  else if(data == "true")
    alert("ok");
});

这篇关于浏览器不停止加载与jQuery $不用彷徨的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆