-2
鏈接:http://localhost:50028/Account/JsonResult方法通過AJAX不調用調用JSON輸出的
我JsonResult以下方法:
[HttpGet]
public JsonResult GetGroupList()
{
try
{
DataConnection store = new DataConnection();
DataTable dt = store.GetDataTable("GetGroupList");
if (dt.Rows.Count > 0)
{
var result = new { Success = "true", Message = Common.SerializeDataTable(dt) };
return Json(result, JsonRequestBehavior.AllowGet);
}
else
{
var result = new { Success = "false", Message = "There is no item in Group list." };
return Json(result, JsonRequestBehavior.AllowGet);
}
}
catch (Exception ex)
{
Common.InsertErrorLog("AccountController", "GetGroupList()", ex.ToString());
var result = new { Success = "false", Message = "Internal Error, Exception occured." };
return Json(result, JsonRequestBehavior.AllowGet);
}
}
的上述下面
{
"Success": "true",
"Message": "[{\"ID\":1,\"TEXT\":\"BANK ACCOUNT\"},{\"ID\":2,\"TEXT\":\"BANK O/D ACCOUNT\"},{\"ID\":3,\"TEXT\":\"CAPITAL ACCOUNT\"},{\"ID\":4,\"TEXT\":\"CASH IN HAND\"},{\"ID\":5,\"TEXT\":\"CURRENT ASSETS\"},{\"ID\":6,\"TEXT\":\"CURRENT LIABILITIES\"},{\"ID\":7,\"TEXT\":\"DIRECT EXPENSES\"},{\"ID\":8,\"TEXT\":\"DIRECT INCOMES\"},{\"ID\":9,\"TEXT\":\"FIXED ASSETS\"},{\"ID\":10,\"TEXT\":\"INDIRECT EXPENSES\"},{\"ID\":11,\"TEXT\":\"INDIRECT INCOME\"},{\"ID\":12,\"TEXT\":\"INVESTMENT\"},{\"ID\":13,\"TEXT\":\"SECURED LOAN\"},{\"ID\":14,\"TEXT\":\"UNSECURED LOAN\"},{\"ID\":15,\"TEXT\":\"PURCHASE ACCOUNTS\"},{\"ID\":16,\"TEXT\":\"SALES ACCOUNT\"},{\"ID\":17,\"TEXT\":\"STOCK IN HAND\"},{\"ID\":18,\"TEXT\":\"SUNDRY CREDITORS\"},{\"ID\":19,\"TEXT\":\"SUNDRY DEBTORS\"},{\"ID\":20,\"TEXT\":\"PROVISIONS\"},{\"ID\":21,\"TEXT\":\"DUTIES AND TAXES\"},{\"ID\":22,\"TEXT\":\"DEPOSIT ACCOUNT\"},{\"ID\":23,\"TEXT\":\"LOANS AND ADVANCES\"},{\"ID\":24,\"TEXT\":\"LOANS LIABILITIES\"},{\"ID\":25,\"TEXT\":\"BANK OCC\"},{\"ID\":26,\"TEXT\":\"BRANCH/DIVISIONS\"},{\"ID\":27,\"TEXT\":\"MISC. EXPENSE (ASSET)\"},{\"ID\":28,\"TEXT\":\"SUSPENSE A/C\"},{\"ID\":29,\"TEXT\":\"RESERVE & SURPLUS\"},{\"ID\":30,\"TEXT\":\"OPENING STOCK\"},{\"ID\":31,\"TEXT\":\"PROFIT & LOSS A/C\"}]"
}
我的AJAX調用MVC jsonresult方法輸出:
$(document).ready(function() {
$.ajax({
type: 'GET',
cache: false,
url: "http://localhost:50028/Account/GetGroupList",
//url: "http://api.ispecial.in/Account/GetGroupList/",
async: true,
contentType: 'application/json; charset=utf-8',
dataType: 'Json',
success: function (response) {
alert('1');
//debugger;
var res = JSON.parse(response).Table;
console.log(res);
//alert(response);
//var res = JSON.parse(response);
//alert(res);
//$("#tbGroupList").append("<tr><td>" + data.d[i].ID + "</td><td>" + data.d[i].TEXT + "</td></tr>");
},
error: function (response) {
alert('error');
console.log(response);
}
});
});
我已經創建了JsonResult [HttpGet]方法,並通過ajax調用我想獲得輸出,但我得到錯誤。
什麼錯誤? –
XML解析錯誤:未找到根元素位置: –
其中是此方法GetGroupList?它是mvc還是web api? –