birwin
asked on
jQuery Ajax function not working
I am trying to use this code, a variation of which I have used successfully in the past, and I can't get it to work. I assume there must be some syntax or logic error that I can't find. Perhaps your eyes can discover it.
<script type=\"text/javascript\">
$(function(){
var vehicle = $("#vehicle");
var pickup = $("#PICKUP");
var error = $("#error");
var postwrap = $("#postwrap");
$("#vsearch").submit(funct ion(){
if((pickup.val() == "") || (dropoff.val() == "")){
error.text("The post must have both a pickup and a dropoff location").fadeIn(300).del ay(900).fa deOut(300) ;
return false;
}
else{
$.ajax({
type: "POST",
url: "AJAX_process.php",
data: "vehicle="+vehicle.val()+" &pickup="+ pickup.val ()+"&add=t rue",
success:
function(r){
postwrap.html(r);
postwrap.hide().show(1000) ;$("#succe ss").text( "Post added").fadeIn(300).delay( 900).fadeO ut(300),
},
error: function(){$("#error").tex t("Could not add post").fadeIn(300).delay(9 00).fadeOu t(300)}
});
return false;
}
}
)});
</script>
The form has the id of vsearch.
With this installed, and the form statement as simple as <form id="vsearch"> (no action statement), the form still refreshes and does not show the result in the divs
I have jQuery running OK on the page, powering some other functions. I am using it in som PHP code.
Any ideas?
<script type=\"text/javascript\">
$(function(){
var vehicle = $("#vehicle");
var pickup = $("#PICKUP");
var error = $("#error");
var postwrap = $("#postwrap");
$("#vsearch").submit(funct
if((pickup.val() == "") || (dropoff.val() == "")){
error.text("The post must have both a pickup and a dropoff location").fadeIn(300).del
return false;
}
else{
$.ajax({
type: "POST",
url: "AJAX_process.php",
data: "vehicle="+vehicle.val()+"
success:
function(r){
postwrap.html(r);
postwrap.hide().show(1000)
},
error: function(){$("#error").tex
});
return false;
}
}
)});
</script>
The form has the id of vsearch.
With this installed, and the form statement as simple as <form id="vsearch"> (no action statement), the form still refreshes and does not show the result in the divs
I have jQuery running OK on the page, powering some other functions. I am using it in som PHP code.
Any ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Glad to help. Thanks for the points.
ASKER
Thank you!