MVC Json Ajax ¶þ¼¶ ¼¶Á¬
<script type="text/javascript">
$(document).ready(function() {
$("#teamName").change(function() {
$.getJSON('/team/SelectProduct', { teamName: $("#teamName").val() }, function(data) {
$("#productID").empty();
$.each(data, function(i, item) {
$("<option></option>")
.val(item)
.text(item)
.appendTo($("#productID"))
});
});
})
});
controller:
public ActionResult SelectProduct()
{
string teamName = Request.Params["teamName"];
int teamID = dc.TestTeams.Where(x => x.Name == teamName).SingleOrDefault().Id;
var productCollection = dc.Products.Where(x => x.TestTeamId == teamID).Select(x=> x.ShortName);
return Json(productCollection);
}
Ïà¹ØÎĵµ£º
¿´¿´ Ajax ºÍ DOM ½Å±¾±à³Ì¾¿¾¹Óжà¼òµ¥
ÎĵµÑ¡Ïî
½«´ËÒ³×÷Ϊµç×ÓÓʼþ·¢ËÍ
¼¶±ð£º Öм¶
Jesse Skinner, Web ¿ª·¢ÈËÔ±, Freelance
2007 Äê 5 ÔÂ 16 ÈÕ
jQuery ÊÇÒ»¸öJavaScript ¿â£¬ËüÓÐÖúÓÚ¼ò»¯ JavaScript™ ÒÔ¼° Asynchronous JavaScript + XML (Ajax) ±à³Ì¡£ÓëÀàËÆµÄ JavaScript ¿â²»Í¬£¬jQuery ......
1. http://hi.baidu.com/lshun/blog/item/2378b4c36fdef455b219a85b.html
CODE:
<?xml version="1.0" encoding="UTF-8"?>
<data>
<pets>
<è />
<¹· />
< ......
´ÓÊý¾Ý¿âmyÖеÄusernameÓû§±íÀïÑéÖ¤£º
checkusername.html£º
<!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>
<meta http-equiv="Content-Type" conte ......
Case I. Web´úÀíµÄ·½Ê½ (on Server A)
¼´Óû§·ÃÎÊAÍøվʱËù²úÉúµÄ¶ÔBÍøÕ¾µÄ¿çÓò·ÃÎÊÇëÇó¾ùÌá½»µ½AÍøÕ¾µÄÖ¸¶¨Ò³Ã棬ÓɸÃÒ³Ãæ´úÌæÓû§Ò³ÃæÍê³É½»»¥£¬´Ó¶ø·µ»ØºÏÊʵĽá¹û¡£´Ë·½°¸¿ÉÒÔ½â¾öÏֽ׶ÎËùÄܹ»Ïëµ½µÄ¶àÊý¿çÓò·ÃÎÊÎÊÌ⣬µ«ÒªÇóAÍøÕ¾ÌṩWeb´úÀíµÄÖ§³Ö£¬Òò´ËAÍøÕ¾ÓëBÍøÕ¾Ö®¼ä±ØÐëÊǽôÃÜÐ×÷µÄ£¬ÇÒÿ´Î½»»¥¹ý³Ì£¬AÍøÕ¾µÄ· ......