Sharpadox
Sharpadox

Reputation: 9

Ajax cant find php file.. Why?

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).

Upvotes: 1

Views: 2710

Answers (2)

amamut
amamut

Reputation: 311

You should be able to load your logreg.php in your browser and get the 'true' message on your screen. So use whatever url to get to your php file, then use the same url in your js file:

url: "http://mydomain.local/logreg.php",

Upvotes: 0

Quentin
Quentin

Reputation: 944441

they are in the same directory

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

Upvotes: 4

Related Questions