Reputation: 9
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
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
Reputation: 944441
they are in the same directory
URLs are relative to the HTML document not the JavaScript file.
Upvotes: 4