在过去的几个小时里,我一直在解决这个问题,但令人沮丧的是找不到解决方案。我正在尝试使用 JQuery .ajax() 函数提交表单,但它没有提交,代码如下,任何建议将不胜感激:
JS:
$(document).ready(function() {
var livelistURL = "/scripts/livelist.php?guestlist=<?php echo $_GET['guestlist']; ?>";
var names = '';
var dot = '.';
$("#livelist").load(livelistURL);
$("input#name").select().focus();
$("#addname").submit(function(event){
event.preventDefault();
$("input#name").blur();
$('#working').show();
$('#event-box').fadeTo('fast', 0.5);
var guestlist = '<?php echo $_GET['guestlist']; ?>';
var name = $('input#name');
var by = '<?php echo $email; ?>';
var data = 'name=' + name.val() + '&guestlist=' + guestlist.val() + '&by=' + by.val();
$("input#name").blur();
$.ajax({
url: "/scripts/addname.php",
type: "post",
data: data,
success: function(){
var value = $("input#name").val().toUpperCase();;
$("span.success").text(value);
if (names == '') {
names = value;
}
else {
names = ' ' + value + ', ' + names;
$("span#dot").text(dot);
}
$("span#name1").text(names);
$('#working').fadeOut('fast');
$('#success').fadeIn('fast');
$('#added-names').fadeIn('fast');
$('#success').delay('600').fadeOut('fast');
$('#event-box').delay('600').fadeTo('fast', 1.0);
},
error: function(){
$('#working').fadeOut('fast');
$('#error').fadeIn('fast');
$('#error').delay('600').fadeOut('fast');
},
complete: function(){
$("input#name").val('');
$("input#name").select().focus();
}
});
});
}); // end
表单 HTML:
<form id="addname">
<input id="name" name="name" class="tagcheck" style="z-index: 1000;" minlength="5" maxlength="60" placeholder="Add Name" />
</form>