关于js提交表单的问题
来源:3-10 作业题
WittChen
2020-05-11 11:06:56
老师您好,学习js也已经有一段时间了,到目前好像还没有讲到,js表单提交到后端的相关内容的知识,我在写后端程序的时候,也经常看前端代码,看的不是特别懂,比如一个表单,点击提交后,它会绑定一个函数,这个函数中会指定提交的数据,提交的方式,提交的到哪个链接等等,如下代码:
$.ajax({ cache: false, type: 'post', dataType:'json', url:"/send_sms/", data:{ mobile:$inpRegMobile.val(), "captcha_1":$inpRegCaptcha.val(), "captcha_0":$('#id_captcha_0').val(), }, async: true, beforeSend:function(XMLHttpRequest){ $sendBtn.val("发送中..."); $sendBtn.attr("disabled","disabled"); }, success: function(data){ $sendBtn.removeAttr("disabled"); $sendBtn.val("发送验证码"); if(data.mobile){ Dml.fun.showValidateError($inpRegMobile, data.mobile); refresh_captcha({"data":{"form_id":"jsRefreshCode"}}); }else if(data.captcha){ Dml.fun.showValidateError($inpRegCaptcha, data.captcha); refresh_captcha({"data":{"form_id":"jsRefreshCode"}}); }else if(data.msg){ Dml.fun.showValidateError($inpRegMobile, data.msg); $sendBtn.val("重新发送"); refresh_captcha({"data":{"form_id":"jsRefreshCode"}}); }else if(data.status == 'success'){ Dml.fun.showErrorTips($tipsId, "短信验证码已发送"); $sendBtn.attr("disabled","disabled"); alert("不好意思!手机验证码短信费用昂贵,网站正在开发阶段为了节约成本,现在直接发送给你了:"+data.code) show_send_sms(60); } } });
如上代码是我的一个小作品中的一段js,前端是别人给的,我写后端,像这种代码,就业班课程中会讲到吗
1回答
同学你好,小作品中使用的是jquery的ajax提交表单数据,该部分内容会在下一阶段的课程中讲到:
如果我的回答帮到了你,欢迎采纳,祝学习愉快!
相似问题