Ajax post in jquery

Source: Internet
Author: User

The following is an Ajax post example. Script part of the code

Ajax post in jquery ------ code
<SCRIPT type = "text/JavaScript">
Function adddata ()
{
VaR typename = $ ("# <% = This. typename. clientid %>"). Val ();
VaR MSG = "not be empty ";
If (typename = "")
{
If (MSG! = "")
{
Alert (MSG );
Return false;
}
}
Else
{
// Display the progress bar
$ ("# Loading"). ajaxstart (function (){
$ (This). Show ();
});

// Events triggered before submission
$ ("# MSG "). ajaxsend (function (request, settings) {$ (this ). append ("<li> starting request at" + settings. URL + "</LI> ");});

// The countryID here can be dynamically retrieved from the gridview
VaR countryID = $ ("# <% = This. drpcountry. clientid %>"). Val (); // obtain the drop-down menu Value
VaR countryname = format_get_name (countryID); // obtain the drop-down menu text
VaR typename = $ ("# <% = This. typename. clientid %>"). Val (); // obtain the value of TXT as typename
VaR showtypedesc = $ ("# <% = This. showtypedesc. clientid %>"). Val (); // obtain the value of TXT as showtypedesc

// Call juqery Ajax
$. Ajax ({
Type: "Post ",
URL: "addnews. aspx ",
Timeout: 20000,
Error: function () {alert ('error ');},
Data: "countryID =" + countryID + "& countryname =" + countryname + "& typename =" + typename + "& showtypedesc =" + showtypedesc,
Success: function (MSG)
{

VaR text = MSG. Split ('<');
// Add an executed method when the Ajax request fails.
$ ("# MSG"). ajaxerror (function (request, settings ){
$ (This). append ("<li> error requesting page" + settings. url + "</LI> ");
});

// Add a method to be executed when the Ajax request is successful
$ ("# MSG"). ajaxsuccess (function (request, settings ){
$ (This). append (Text [0]);
});

// Clear the values in the text
$ ("# <% = This. typename. clientid %>"). Val ("");
$ ("# <% = This. showtypedesc. clientid %>"). Val ("");
Return false;
}
});
}
}

// Obtain the text content from the drop-down menu
Function format_get_name (ID)
{
VaR DRP = $ ('<% = drpcountry. clientid %> ');
For (VAR I = 0; I <DRP. Options. length; I ++)
{
If (DRP. Options [I]. value = ID)
{
Return DRP. Options [I]. text;
}
}
Return '';
}
</SCRIPT>

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.