请教个JSON异步获取的问题
后台代码
[HttpPost]
public JsonResult GetShipId()
{
var ship = db.chartered_ship_base_info.ToList();
StringBuilder sb = new StringBuilder();
sb.Append("<option value=\"-1\">select....</option>");
foreach (var item in ship)
{
sb.AppendFormat("<option value=\"{0}\">{1}</option>", item.chartered_ship_number, item.chartered_ship_number);
}
string result = sb.ToString();
return this.Json(result, JsonRequestBehavior.AllowGet);
}
[HttpPost]
public JsonResult GetCabinId(string shipnumber)
{
var cabin = db.ship_cabin_info.Where(c => c.chartered_ship_number == shipnumber).ToList();
StringBuilder sb = new StringBuilder();
sb.Append("<option value=\"-1\">select.....</option>");
foreach (var item in cabin)
{
sb.AppendFormat("<option value=\"{0}\">{1}</option>", item.cabin_number, item.cabin_number);
}
string result = sb.ToString();
return this.Json(result, JsonRequestBehavior.AllowGet);
}
前台代码
<script type="text/javascript">
$(function () {
$.ajax({
url: "/TestJosn/GetShipId",
type: "POST",
contentType: "application/json; charset=utf-8",
data: "{}",
dataType: "json",
success: function (data)