模式1 ajax url传参,gin使用Query
========== js ===============
var request = new XMLHttpRequest();
request.open("POST", "/get_verify?mobile="+mobile.value);
request.setRequestHeader("Content-Type","application/x-www-urlencode");
request.onreadystatechange = function() {
if(this.readyState === 4 && this.status === 200) {
console.log( request.responseText)
}else{
}
};
request.send()
=========== gin ================
func GetVerify(c *gin.Context){
mobile := c.Query("mobile")
fmt.Println("mobile=",mobile)
}
模式2 ajax send()发送,gin GetRawData()接受
============= js ==============
var request = new XMLHttpRequest();
request.open("POST", "/get_verify?mobile="+mobile.value);
request.setRequestHeader("Content-Type","application/x-www-urlencode");
request.onreadystatechange = function() {
if(this.readyState === 4 && this.status === 200) {
console.log( request.responseText)
}else{
}
};
request.send()
========== gin ==========
func GetVerify(c *gin.Context){
mobile := c.GetRawData
fmt.Println("mobile=",mobile)
}