麻烦大神看看这段ajax怎么不发送请求

红尘无爱 2017-08-26 12:08:47


$(function () {
if ($("#comment-box").length > 0) {
alert(infoid);
$.ajax({

type : "post",
cache : false,
url : webroot + "http://www..com/comment.php?act=islogin",
data : "gourl=" + contenturl,
success : function (_) {
$("#comment-box").html(_);
checkcomment()
}
})
}
if ($("#comments").length > 0) {
$.ajax({
type : "post",
cache : false,
url : webroot + "http://www..com/comment.php?act=load&id=" + infoid,
success : function (_) {
$("#comments").html(_)
}
})
}
});








...全文
487 24 打赏 收藏 转发到动态 举报
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
红尘无爱 2017-09-01
  • 打赏
  • 举报
回复
引用 23 楼 lh460795 的回复:
你js 是test.php 然后你ajax 又请求 test.php ? 然后 你test.php什么 输出都没有 肯定是空啊
可我改成请求test111.php 它不是应该给我来个 请求的 404错误吗。改成test111.php 也是啥都没有呀
lh460795 2017-09-01
  • 打赏
  • 举报
回复
你js 是test.php 然后你ajax 又请求 test.php ? 然后 你test.php什么 输出都没有 肯定是空啊
红尘无爱 2017-09-01
  • 打赏
  • 举报
回复
大神快来
qq_34494805 2017-08-31
  • 打赏
  • 举报
回复
换个原生的看看吧
红尘无爱 2017-08-29
  • 打赏
  • 举报
回复
找到了 <script>var webroot="/";</script> 申明的 是一个根目录
红尘无爱 2017-08-29
  • 打赏
  • 举报
回复
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.js"></script>
<script type="text/javascript">
$(function () {
$.ajax({

type : "post",
cache : false,
url : "http://a.com/test.php?act=islogin",
data : "gourl=" + contenturl,
success : function (_) {
$("#comment-box").html(_);
checkcomment()
}
})
});
</script>



晕,还是没有请求出去数据呀
红尘无爱 2017-08-29
  • 打赏
  • 举报
回复
引用 17 楼 hongmei85 的回复:
去掉webroot
谢谢,请问下 webroot会是什么呢, 一般什么会放在前面呀 所有JS文件 我都搜索了 就是找不到 webroot 的申明
hongmei85 2017-08-29
  • 打赏
  • 举报
回复
去掉webroot

<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.js"></script>
<script type="text/javascript">
$(function () {  
 
   // if ($("#comment-box").length > 0) {
         
        $.ajax({
              
            type : "post",
            cache : false,
            url : "http://a.com/test.php?act=islogin",
            data : "gourl=" + contenturl,
            success : function (_) {
                $("#comment-box").html(_);
                checkcomment()
            }
        })
    //}
   // if ($("#comments").length > 0) {
       /* $.ajax({
            type : "post",
            cache : false,
            url : "http://a.com/comment.php?act=load&id=" + infoid,
            success : function (_) {
                $("#comments").html(_)
            }
        })*/
    //}
});
</script>
红尘无爱 2017-08-29
  • 打赏
  • 举报
回复
错了,找了半天也没找见 .webroot 是什么, 能直接改成可以发送的吗
红尘无爱 2017-08-29
  • 打赏
  • 举报
回复
var css = webroot + "styles/style.css";
引用 14 楼 szuzsq 的回复:
好着急.每个人都懂,就楼主不懂. BTW:已经有3次以上别人提到,webroot是什么东西了.楼主愣是没回答.
qq_27991461 2017-08-28
  • 打赏
  • 举报
回复
jsonp跨域,而且你的data数据的是文本字符,再者你的webroot代表什么,后面的是http://。。的一个url地址了
szuzsq 2017-08-28
  • 打赏
  • 举报
回复
好着急.每个人都懂,就楼主不懂. BTW:已经有3次以上别人提到,webroot是什么东西了.楼主愣是没回答.
红尘无爱 2017-08-27
  • 打赏
  • 举报
回复
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.js"></script>
<script type="text/javascript">
$(function () {  

   // if ($("#comment-box").length > 0) {
        
        $.ajax({
             
            type : "post",
            cache : false,
            url : webroot + "http://a.com/test.php?act=islogin",
            data : "gourl=" + contenturl,
            success : function (_) {
                $("#comment-box").html(_);
                checkcomment()
            }
        })
    //}
   // if ($("#comments").length > 0) {
       /* $.ajax({
            type : "post",
            cache : false,
            url : webroot + "http://www..com/comment.php?act=load&id=" + infoid,
            success : function (_) {
                $("#comments").html(_)
            }
        })*/
    //}
});
</script>
是不是还要封装这个方法呀,好像也不是呀, 这是扒拉别个网站的,他里面好像就没有封装啥方法呀
xuzuning 2017-08-27
  • 打赏
  • 举报
回复
只贴图,不贴代码 心不诚啊!
红尘无爱 2017-08-27
  • 打赏
  • 举报
回复
怪呀,为啥就是没发送请求呀

xuzuning 2017-08-27
  • 打赏
  • 举报
回复
你的程序运行地址
ajax目标地址
域名不相同,这就是跨域
红尘无爱 2017-08-27
  • 打赏
  • 举报
回复
url : webroot + "http://a.com/comment.php?act=islogin", 改这样了 也不见有请求发送出去,呀,呀 呀
红尘无爱 2017-08-27
  • 打赏
  • 举报
回复
引用 4 楼 xuzuning 的回复:
跨域了! AJAX 是不能跨域工作的
大大啥意思呀, http://apps.bdimg.com/libs/jquery/1.9.1/jquery.js 这个文件我要下载回来 放自己服务器上嘛
红尘无爱 2017-08-27
  • 打赏
  • 举报
回复


判断去了 也是没见到有请求发出去
xuzuning 2017-08-27
  • 打赏
  • 举报
回复
跨域了! AJAX 是不能跨域工作的
加载更多回复(3)

20,359

社区成员

发帖
与我相关
我的任务
社区描述
“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
phpphpstorm 技术论坛(原bbs)
社区管理员
  • 开源资源社区
  • phpstory
  • xuzuning
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧