For some reason I can't get this to work. All I want to do is that when a button is clicked, (via ajax) a php file is executed. Aka, if I weren't using ajax, we'd be looking at:
<a href="file.php">dfgdfg</a>
I want the file to be executed without leaving the page.
This is what I've got atm:
$(".vote-up").live('click', function(e) {
$.ajax("file.php", function(){
alert("Executed file");
});
});
That doesn't seem to be working. I'm just really confused how the jQuery ajax function functions in general, without dealing with anything remotely complicated.
Added question:
.ajax({
url: 'includes/login-check-jquery.php',
success: function (data) {
if(data == 1){
alert("Logged in!!!");
}else{
window.location = data;
}
error: function (xhr, status, error) {
// executed if something went wrong during call
if (xhr.status > 0) alert('Error: ' + status); // status 0 - when load is interrupted
}
});
});
In the above code, if the data returned equals "logged in" than a message box appears. Otherwise it'll redirect to the location (that is sent in data). For some reason this if statement isn't working, but the data is being returned as expected.
My PHP code is:
<?php
if (!$user->logged_in){
echo "../login/index.php";
}else{
echo "1";
}
?>
Any ideas?
livewithonbecause live is deprecated ! also check that the path to the php file is correctwindow.location: developer.mozilla.org/en-US/docs/DOM/window.location