Ajax commits the presentation of data to the background

Source: Internet
Author: User

Today it took almost a day to do the form of the value and save to the database, display, as a small progress of their own, notes down, look more.

is similar to the post message feature:

Front Code:

<div id= "Dialog" class= "animated" >

<div class= "Dialogtop" >
<span style= "Float:left; Color: #808080; " > Questions </span>
<a href= "javascript:;" class= "clasedialogbtn" > Close </a>
</div>
<form action= "" method= "Post" id= "EditForm" name= "AddForm" >
<ul class= "Editinfos" style= "padding:0px;" >
<li><input type= "text" name= "nickname" id= "Nick" style= "width:90%;height:30px;border:1px solid RGB (169, 169, 169); BORDER-RADIUS:4PX, "placeholder=" Please enter the name "/></li> "
<li><textarea style= "width:90%;height:100px; border-radius:4px;" Placeholder= "Please enter your question ~" id= "Questxt" Name= "Question" ></textarea></li>

<li><input type= "Submit" value= "Confirm Submit" class= "submitbtn" id= "AddMessage"/></li>
</ul>
</form>
</div>

Color labeling is the main code ...

Ajax:

<script>
$ (' #AddMessage '). Click (function () {
var name = $ (' #nick '). Val ();
var question = $ (' #questxt '). Val ();
$.ajax ({
Type: "POST",
URL: '/default/addmessage ',
Cache:true,
Async:false,
Data: {
Quizzer:name,
Question:question,
},
Success:function (data) {
Alert ("Submit success!");
},
Error:function () {
Alert (' Submit failed! ‘);
}
});
});

</script>

The following is the code inside the C # MVC controller:

<summary>
Release
</summary>
<param name= "Id" ></param>
<param name= "Quizzer" > Nickname </param>
<param name= "Question" > Questions </param>
<param name= "Questiontime" > Message time </param>
<returns></returns>
[HttpPost]
public void AddMessage (String quizzer,string Question)
{
QandA QandA = new QandA ();

QandA. Quizzer = Quizzer;
QandA. Question = Question;
QandA. Questiontime = DateTime.Now;
Db. Qandas.add (QandA);
Db. SaveChanges ();
}

I hope I will make more progress in the future.

Ajax commits the presentation of data to the background

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.