[英]I want to use the data in the Controller in the View side javascript
this is my controller:这是我的 controller:
public ActionResult AjaxSmsSend(Sms smsInfo)
{
var sms = smsInfo.smsCode;
var telephone = smsInfo.telephone;
ViewBag.Code = sms;
return Json(sms);
}
In the View:在视图中:
<button id="getDataBtn">Click me</button>
When I press this button:当我按下这个按钮时:
<script type="text/javascript">
$(function () {
$("#getDataBtn").click(function () {
$.ajax({
type: "GET",
url: "/Home/AjaxSmsSend",
data: sms,
contentType: "application/json; charset=utf-8",
dataType: "json",
});
});
</script>
I will use it to compare the sms data I received from the controller.我将使用它来比较从 controller 收到的短信数据。
<p style="text-align: center;margin-top: 10%;">Enter your sms code</p>
<input type="text" id="pincode" maxlength="4">
This input is entered by the user.该输入由用户输入。 I have generated sms data in the controller itself.
我在 controller 本身中生成了短信数据。
I'm sure it's actually a very simple process.我确信这实际上是一个非常简单的过程。 But since I've just started, I can't find what I'm looking for.
但由于我刚刚开始,我找不到我要找的东西。 I'd appreciate it if you could help me with that.
如果您能帮助我,我将不胜感激。
I don't think it's a good practice, normaly the comparison should in server side but you can Add this:我认为这不是一个好习惯,通常比较应该在服务器端,但你可以添加这个:
success: function (response) {
if (response.smsCode)
{
}
}
it will be like this:它会是这样的:
<script type="text/javascript">
$(function () {
$("#getDataBtn").click(function () {
$.ajax({
type: "GET",
url: "/Home/AjaxSmsSend",
data: sms,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
if (response.smsCode)
{
}
}
});
});
</script>
Then put your code inside this if:然后将您的代码放入其中,如果:
if (response.smsCode)
{
}
That's all, I hope you find this helpful就是这样,希望对您有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.