uniapp提交数据相关问题
uniapp提交数据相关问题记录
1、uni.request提交数据
uni.request({
method:"POST",
data:{
code:"0000",
message:"操作成功"
},
url: this.$baseUrl.baseUrl+'ModifyPswd/modifyPasswordTips',
success : (res) =>{
},
fail : (res) =>{
}
})
向后台提交数据,可以得到相应的响应,但是无法进行跳转页面
2、使用js,前端生成form表单进行提交
let url = this.$baseUrl.baseUrl+'ModifyPswd/modifyPasswordTips';
var data = {"code":"0000","message":"操作成功"};
this.postUrl(url,"POST",data);
/*
* url:跳转链接
* method:跳转方式
* params:传递参数 [{name:"test" ,data:"123"}]
* */
postUrl(URL,METHOD,PARAMS) {
var tmp_form = document.createElement("form");
tmp_form.action = URL;
tmp_form.method = METHOD;
// form.enctype = "multipart/form-data";
tmp_form.style.display = "none";
for (var x in PARAMS) {
var opt = document.createElement("input");
opt.name = x;
opt.value = PARAMS[x];
tmp_form.appendChild(opt);
}
document.body.appendChild(tmp_form);
tmp_form.submit();
document.body.removeChild(tmp_form);
}
自定义的js函数,动态创建form表单,向后台提交数据,可以进行后台的页面跳转,但是无法进行获取相应的响应
3、C# 相关后端代码
public ActionResult modifyPasswordTips()
{
string code = GetRequestString("code");
string message = GetRequestString("message");
//string reUrl = WxConfig.CallbackUrl + "/wxfront/index.html";
//Session["path"] = "person/healthcard/healthcard";
Session["path"] = "Views/Begin/index.html#/pages/index/MotifyTips/MotifyTips";
string url = "{0}/{1}?code={2}&message={3}";
//url = string.Format(url, WxConfig.CallbackUrl, Session["path"], "0000", "操作成功");
url = string.Format(url, WxConfig.CallbackUrl, Session["path"], code, message);
base.Response.Redirect(url,false);
return View("/Views/Begin/Index.cshtml");//映射其他页面的视图
}
private string GetRequestString(string key)
{
string result = null;
if (base.Request.Form.Get(key) != null && base.Request.Form.Get(key).ToString() != "")
{
result = base.Request.Form.Get(key).ToString();
}
else if (base.Request.QueryString[key] != null && base.Request.QueryString[key].ToString() != "")
{
result = base.Request.QueryString[key].ToString();
}
else if (base.Request.HttpMethod.ToUpper() == "POST")
{
try
{
using (System.IO.StreamReader sr = new System.IO.StreamReader(Request.InputStream, Encoding.UTF8, true, 2048, true))
{
string inputStream = sr.ReadToEnd();
JObject jsonObj = JObject.Parse(inputStream);
if (jsonObj != null)
{
result = Convert.ToString(jsonObj[key]);
}
Request.InputStream.Position = 0;
}
}
catch (Exception ex)
{
LogHelper.LogError("从Post参数中获取数据出现异常", ex);
return null;
}
}
return result;
}
}