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>