JQuery AJAX post not working if more than 1 function is defined
I have a JQUERY AJAX post function that will work if there is one function, but if I try and include another function in addition, the second function does not post through to the .PHP script. I am a beginner in JQUERY but have tried every variation, but it will process the first function, but if I add any other functions, will not process those.
<script language="javascript" type="text/javascript">
function toggle[My CSS code](x) {
if ($('#'+x).is(":hidden")) {
$('#'+x).slideDown(400);
} else {
$('#'+x).hide();
}
$('.[My CSS Code]').hide();
}
function add(a,b){
var URL="process.php";
$("#add").text("Processing").show();
$.post(URL,{request:"request",mem1:a,mem2:b,},function(data){
$("#add").html(data).show().fadeOut(12000);
});
}
/////This is where the code stops working and the .php script doesnt work//////////
function accept (x) {
var URL="process.php";
$.post(URL,{ request: "accept", reqID: x, } ,function(data) {
$("#req"+requestID).html('<font color="#000">Accepted</font>').show();
});
}
function deny (x) {
var URL="process.php";
$.post(URL,{ request: "deny", reqID: x, } ,function(data) {
$("#req"+x).html('denied').show();
});
}
</script>
So it will process the add f开发者_如何学Cunction but not the accept nor deny function via the URL posted in the add. Any ideas would be greatly appreciated. Thanks!
You are only defining the URL in the first function, and it's var'ed so the other functions don't have access and have an undefined url
Depending on which browser you are using the trailing comma in your ajax options object may be causing a problem:
// this little guy
// |
// v
$.post(URL,{request:"request",mem1:a,mem2:b,},function(data){
I have known IE to choke on trailing commas in object or array definitions, though FF and Chrome usually seem to be able to handle it
精彩评论