Home > front end >  Button on the ajax request is less than the controller inside
Button on the ajax request is less than the controller inside

Time:09-17

front-end code
 






Id="BTN" onclick="time" (this) & gt; Get verification code







the ajax request, here is layui framework
 
<script SRC="https://bbs.csdn.net/topics/resource/layuiadmin/layui/layui.js" & gt; </script>
<script>
Layui. Config ({
Base: 'the resource/layuiadmin///static resource path
}). The extend ({
Index: 'lib/index//the main entry module
}). Use ([' index ', 'user'], function () {
Var $=layui. $
, the setter=layui setter
Admin=layui. Admin
, form=layui. Form
, the router=layui. The router ()
, search=the router. The search;

form.render();


//$(" body ") on (" click ", "# get - vercode", function () {
//alert (1);
//});

$(" # get - vercode "). Click (function () {
This. SRC="https://bbs.csdn.net/topics/system/admin/validateCode? T="+ (new Date). GetTime ();
});

//submit
Form. On (' submit (user - login - submit), function (data) {

The doLogin (data field);

});

/* *
* deposit characters form
* @ returns
*/

The function the doLogin (params) {
Var index=layer. The load (1, 0.7} {shade:);
$. Ajax ({
Type: "post",
Url: 'the system/admin/the dologin',
DataType: "json",
Traditional: true,
//set the contentType type to json
//contentType: 'application/json; Charset=utf-8 ',
//the json data
Data: params,
//callback function after the request is successful
Success: the function (data) {
layer.close(index);
If (data. Success) {

Layer. MSG (data. MSG, {
Offset: 'auto'
1
, icon:Shade: 0.3
, shadeClose: true
The anim: 1
Time: 2000
},
The function () {
The location. The href='https://bbs.csdn.net/system/admin/index';
});

//the background page
} else {

Layer. MSG (data. MSG, {
Offset: 'auto'
, 2 icon:
Shade: 0.3
, shadeClose: true
The anim: 1
});
}
},
Error: function () {
layer.close(index);
Layer. MSG (" network request failed!" , {
Offset: 'auto'
, 2 icon:
Shade: 0.3
, shadeClose: true
The anim: 1
});
}
});
}


/* *
* message authentication code
* @ type {string}
*/
Var SMS="";
$(" # "BTN). Click (function () {
Var phone=$(" # phone "). Val ();
If (phone! {
="")$. Ajax ({
Type: "POST",
URL: "/smscode sendsms/logged",//send the request admin/core/arm/controller \ SmsCodeController system/core/arm/controller/sendsms
Data: {
SmsType: "1004",
Phone: phone
},
Success: the function (res) {
SMS=res;
}
});
} else {
Alert (" please enter the phone number ");
return false;
}
});
$(" # lo "). Click (function () {
Var code=$(" # code "). Val ();
If (code=="") {
Alert (" please enter the verification code ");
} else {
If (SMS==code) {
Window. The location. Href="https://bbs.csdn.net/topics/success.jsp";
} else {
Alert (" verification code error ");
};
};
});

});

</script>


controller
 package com. ZWH. Admin. Core. Arm controller. The index; 

The import com. Yhzq. Base. CCL. Datastructure. Dto;
Import com. Yhzq. Base. CCL. Datastructure, impl. ResponseDto;
The import com. Yhzq. Base. MVC. BaseController;
The import com.yhzq.com mon. Service. Core. SmsCodeService;
The import org. Springframework. HTTP. MediaType;
The import org. Springframework. Stereotype. The Controller;
import org.springframework.web.bind.annotation.RequestMapping;
The import org. Springframework. Web. Bind. The annotation. ResponseBody;

The import javax.mail. The annotation. The Resource;

/* *
*
* function description text controller
*
* @ author chenshuai QQ: 394785275
* @ date 2019/1/2 when
*/
@ Controller
@ RequestMapping ("/smscode ")
Public class SmsCodeController extends BaseController {

@ the Resource (name="smsCodeService")
Private SmsCodeService SmsCodeService;

@ RequestMapping (value="https://bbs.csdn.net/sendsms/logged", produces=MediaType. APPLICATION_JSON_UTF8_VALUE)
@ ResponseBody
Public Object sendSms () throws the Exception {
Dto PDto=super. GetParamAsDto ();
ResponseDto ResponseDto=super. NewResponseDto ();
SmsCodeService. SendMsg (responseDto, pDto getAsInteger (" smsType "), pDto. GetAsString (" receiver "), pDto);
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • Ajax
  • Related