I am using jQuery
and AJAX
to run PHP
functions without refreshing the page. It was working fine for my first two instances but I added a new one an now the new instance keeps giving me the following error
POST http://www.example.com/ajax.php 404 (Not Found)
I checked and rechecked and try to fin a similar error somewhere else by I am stumped. Here is my html
<img id="green" src="http://www.example.com/image/sign_no.jpg" onclick="runAjax(this.id)" />
<span id="blue" onclick="runAjax(this.id)">Press Here</span>
Here is my jQuery code
<script language="javascript">
function runAjax(id) {
if (id == "green") {
if (document.getElementById("green").src == "http://www.example.com/image/sign_no.jpg") {
document.getElementById("green").src = "http://www.example.com/image/sign_yes.jpg";
$.ajax({
type: "POST",
url: "/ajax.php",
data:{action:"green_pressed",user_id:"' . $user_id . '"},
success:function(html) {
alert(id);
}
});
}
}
else if (id == "blue") {
$.ajax({
type: "POST",
url: "/ajax.php",
data:{action:"blue_pressed",run_id:"' . $run_id . '"},
success:function(html) {
alert(id);
}
});
}
}
</script>
This is the ajax.php file
if($_POST['action'] == 'green_pressed') {
print_r($_POST['user_id']);
}
if($_POST['action'] == 'blue_pressed') {
print_r($_POST['run_id']);
}
So when I press the green
id there is no issues, the code runs fine but when I press the blue
id there is where I get the error. Any insights?