weixin_33737134 2014-11-05 13:50 采纳率: 0%
浏览 120

Ajax找不到php文件。为什么?

I am trying to create a ajax-login-form, but my jquery-script cant find the php file. they are in the same directory (!), but it doesn't work.

my php-file (logreg.php)

<?php
    echo 'true';
?>

my script-file (logreg.js)

$("button[action=\"register\"]").click(function(){
    var username = $("#login-username").val();
    var password = $("#login-password").val();
    var repassword = $("#login-repassword").val();
    $.ajax({
        type: "POST",
        url: "logreg.php",
        data: "name="+username+"&pass="+password+"&repass="+repassword,
        success:function(html){
            if(html=='true'){

            }
        },
        beforeSend:function(){
            $("button[action=\"register\"]").text("Sendet ...");
        },
        error: function(ts) { $("div#content").html(ts.responseText); }
    });
});

why isnt this working? i am getting everytime "Error 404" (not found).

  • 写回答

2条回答 默认 最新

  • 三生石@ 2014-11-05 13:54
    关注

    they are in the same directory

    URLs are relative to the HTML document not the JavaScript file.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?
  • ¥15 大智慧怎么编写一个选股程序
  • ¥100 python 调用 cgps 命令获取 实时位置信息
  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
  • ¥15 C语言使用vscode编码错误
  • ¥15 用KSV5转成本时,如何不生成那笔中间凭证
  • ¥20 ensp怎么配置让PC1和PC2通讯上
  • ¥50 有没有适合匹配类似图中的运动规律的图像处理算法
  • ¥15 dnat基础问题,本机发出,别人返回的包,不能命中
  • ¥15 请各位帮我看看是哪里出了问题