sara_t
چهارشنبه 10 خرداد 1396, 09:38 صبح
سلام دوستان من در لایوت یک اینپوت و یک باتن دارم که میخام توسط Ajax مقدار اینپوت رو زمانیکه بر روی باتن کلیک میشه به سرور post کنم.ولی برنامه اصلن جواب نمیده؟ممنون میشم اشکال این کد رو بگید.
کد لایوت:
<div >
<input id="EmailInput" type="text">
<button id="btnaddemail" type="button">ثبت ایمیل</button>
</div>
<script type="text/javascript">
$(function () {
$(".btnaddemail").click(function () {
var email = $("#EmailInput").val();
$.ajax({
url: "/Home/AddEmail",
data: { Email: email },
type: "Post",
success: function () {
alert('Successfully connected to the server');
},
error: function () {
alert('Something went wrong');
}
});
});
});
</script>
@RenderSection("scripts", false)
این هم از کنترلر home:
public ActionResult AddEmail(string Email )
{
db.AddEmail(Email);
return MessageBox.Show("ایمیل شما با موفقیت ثبت شد", MessageType.Success);
}
کد لایوت:
<div >
<input id="EmailInput" type="text">
<button id="btnaddemail" type="button">ثبت ایمیل</button>
</div>
<script type="text/javascript">
$(function () {
$(".btnaddemail").click(function () {
var email = $("#EmailInput").val();
$.ajax({
url: "/Home/AddEmail",
data: { Email: email },
type: "Post",
success: function () {
alert('Successfully connected to the server');
},
error: function () {
alert('Something went wrong');
}
});
});
});
</script>
@RenderSection("scripts", false)
این هم از کنترلر home:
public ActionResult AddEmail(string Email )
{
db.AddEmail(Email);
return MessageBox.Show("ایمیل شما با موفقیت ثبت شد", MessageType.Success);
}