用jQuery获取到前台input text的值,如何将获取到的值传到后台?
答案:3 悬赏:50
解决时间 2021-02-17 22:17
- 提问者网友:太高姿态
- 2021-02-17 10:10
用jQuery获取到前台input text的值,如何将获取到的值传到后台?
最佳答案
暂无最佳答案
全部回答
- 1楼网友:洒脱疯子
- 2021-02-17 12:53
用jquery的ajax啊,
$.ajax({
url: 'abc',
type: 'post',
dataType: 'json',
success:function(){}
})
$.ajax({
url: 'abc',
type: 'post',
dataType: 'json',
success:function(){}
})
- 2楼网友:空山清雨
- 2021-02-17 12:00
前台验证用validator.js就可以,具体请查找百度
后台用django的form验证(我猜你使用的django框架开发的web应用)
具体写法是class LoginForm(ModelForm):
class Meta:
model = Login
fields = {'user_name', 'password'}
def clean(self):
cleaned_data = super(LoginForm, self).clean()
user_name= cleaned_data.get('user_name', '')
password= cleaned_data.get('password', '')
if user_name== '':
self._errors["user_name"] = self.error_class([u'姓名不允许为空!'])
if password== '':
self._errors["password"] = self.error_class([u'密码不允许为空!'])
return cleaned_data
这样在表单提交的时候django的form会自动为你做非空验证,如果有其他需要验证的,可以按照上面的写法进行修改。
- 3楼网友:爱难随人意
- 2021-02-17 11:00
可以使用ajax把获取到的数据传到后台$.post("这里是后台处理页面地址例:(url.php)",{UserName:UserName,UserPwd:UserPwd},function(result){
//这里对返回结果做处理
console.log(result);
});
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯