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.

    评论

报告相同问题?