Jquery ajax partial no refresh update data implementation case
- 2020-03-30 01:38:35
- OfStack
Page to be updated
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="js/jquery.js" type="text/javascript"></script>
</head>
<body>
<select id="lucky1" onchange="return duoduo();">
<option value="1"> The first phase </option>
<option value="2"> The second phase of the </option>
</select>
<div id="duoduo">
hello </div>
<input type="text" id="duo" />
</body>
<script type="text/javascript">
function duoduo() {
$.ajax({
type: 'post', //Optional get
url: 'ajax.aspx', //Here is the program that receives the data
data: 'data=' + $("#lucky1").val(), //Data passed to PHP with multiple arguments connected by &
dataType: 'html', //The data type returned by the server is optional XML,Json jsonp script HTML text, etc
success: function(msg) {
//Here is the data handling function returned by the program after a successful ajax submission. MSG is the returned data, and the dataType is defined in the dataType parameter!
document.getElementByIdx_x_x("duoduo").innerHTML = msg;
//$("#duoduo").innerHTML = msg;
},
error: function() {
alert(' I'm sorry. It failed. ');
}
})
}
</script>
</html>
The operation page
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Params["data"].ToString().Equals("1"))
{
Response.Write("<a href="http://www.baidu.com"> The first phase </a>");
}
else if (Request.Params["data"].ToString().Equals("2"))
{
Response.Write("<a href="http://www.baidu.com"> The first 2 period </a>");
}
}