jquery一个函数来发送所有表单并获取数据
所以我的目标是在我的 jQuery 代码中有一个函数,它允许我执行 case 语句,然后允许我对每个表单执行我需要的操作,而无需重新输入整个 post 函数。
更新我的修复位于这个问题的最底部,
例如
function fetch(e,formstring)
{
$.ajax({
type: 'POST',
url: 'system/classes/core.php',
data: formstring,
dataType: 'json',
contentType: "application/x-www-form-urlencoded;charset=utf-8",
success: function(data){
$.each(data, function(i, obj) {
switch (e) {
case 1:
$.each(obj, function(key, val) {
alert(key+" - "+val);
});
break;
case 2:
alert("sucker");
break;
case 3:
//LoginSript
$('#rightheader').html(obj.code);
break;
case 4:
//WelcomePage/Signup
$('#window').html(obj.code);
break;
}
});
},
error: function(data){
$.each(data,function(i,myinfo){
alert(i);
});
}
});
return false;
}
虽然获取数据似乎有效,但提交表单似乎无效。
$(function() {
$("form#login").submit(function(){
shownotify(1,"Please hold we are login you in.");
fetch(1,$(this).serialize());
});
});
我以为我做的一切都是对的。
同样,您也可以在这里看到显示通知功能。
function shownotify(e,msg)
{
if(e==1){$('#notify').show();};
if(e==2){$('#notify').hide();};
$('#notifyheader').html("Please Hold");
$('#notifytext').html(msg);
}
我想知道我是否有错误,或者我做错了什么?
So my goal was to have a function in my jQuery code, that allowed me to do case statements that then allowed me to do what I needed with each form, without having to re-type the whole post function.
UPDATE my fix is at the very bottom of this question
e.g.
function fetch(e,formstring)
{
$.ajax({
type: 'POST',
url: 'system/classes/core.php',
data: formstring,
dataType: 'json',
contentType: "application/x-www-form-urlencoded;charset=utf-8",
success: function(data){
$.each(data, function(i, obj) {
switch (e) {
case 1:
$.each(obj, function(key, val) {
alert(key+" - "+val);
});
break;
case 2:
alert("sucker");
break;
case 3:
//LoginSript
$('#rightheader').html(obj.code);
break;
case 4:
//WelcomePage/Signup
$('#window').html(obj.code);
break;
}
});
},
error: function(data){
$.each(data,function(i,myinfo){
alert(i);
});
}
});
return false;
}
While fetching data seems to work, submitting forms seems not.
$(function() {
$("form#login").submit(function(){
shownotify(1,"Please hold we are login you in.");
fetch(1,$(this).serialize());
});
});
I thought I was doing everything right.
just also so you can see here is the show notify function too.
function shownotify(e,msg)
{
if(e==1){$('#notify').show();};
if(e==2){$('#notify').hide();};
$('#notifyheader').html("Please Hold");
$('#notifytext').html(msg);
}
I am wondering if I have an error, or am I doing this wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我修复错误的方法是在 $(function(){}) 周围设置 setTimeout 函数
The way I fixed the error was by setting a setTimeout function around the $(function(){})