JSON determines whether the value of the text box already exists in the database

Source: Internet
Author: User

Attribution: Song等

I first write a blog, if there is any wrong place, please point out, also hope that many forgive me, or there are more simple methods, hope the great God, thank you!

Form

@using (Html.BeginForm ("Stockitemsins", "Stockitems", FormMethod.Post, new {id = "search"}))

<input class= "Input-small" type= "text" style= "width:283px" id= "Stock_name" name= "Stock_name" value= "@Model. STOCK_ NAME "/>

Properties of text boxes

<input type= "button" id= "Submit" value= "OK" class= "btn btn-primary"/>

var Model = {}; Define a variable
Model.stock_name = $ (' #STOCK_NAME '). Val (); Get the value of a text box

$.ajax ({
Type: "POST",//Submission method
URL: "@Url. Action (" Checkstock ")",//Submit Path
Data: {
"Stock_name": model.stock_name,//Submit data
},//data, which is used in JSON format for transmission
Success:function (Result) {//Return data is processed according to the result; Get background data processing result
if (result = = "0") {//Determine if the returned data meets the criteria
$ (' #search '). Submit (); Submit data if eligible
Alert ("Data submitted successfully!")                  "); Pop-up window tips
}
else {
Alert ("This XX already exists!")                     "); Does not meet the criteria
}
}//Data processing in the background it's not written.
});

JSON determines whether the value of the text box already exists in the database

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.