本文介绍了Json $ .post或.ajax或.getJSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在ASP.NET MVC2项目中工作.但是我遇到了一个问题,当我从控制器调用并获取异步数据时,该数据将在执行下一条语句后出现.
I am working in ASP.NET MVC2 project. But I have faced a problem that when I call and get asynchronus data from controller that would come after execution of my next statements.
//Jquery part------------
//this folowing method is not working properly for population SET_QualityTestCollection,
//but if i check it after execution(3-5 second delay) this mehod i am getting data for SET_QualityTestCollection
$(document).ready(function () {
var collection = new GetCollectionYS_POTestItemForGrid();
});
var SET_QualityTestCollection = [];
function GetCollectionYS_POTestItemForGrid() {
this.InsertUser = $("#ViewYS_POTestItem_YS_POTestItem_InsertUser").val() == null ? "" : $("#ViewYS_POTestItem_YS_POTestItem_InsertUser").val();
this.Test = "<select id=\"ddlTest_" + YS_POTestItemCurrentID + "\" class = \"ddlQualityTest\" önchange=\"TestRequirementsByTestId(" + YS_POTestItemCurrentID + ")\">" + SetCollectionForDdl() + "</select>";
this.TestRequirment = "<select id=\"ddlRequirements_" + YS_POTestItemCurrentID + "\" class = \"ddlTestRequirements\"><option value='" + 0 + "' \selected=\"selected\">...Select Requirements...</option></select>";
this.TestMethod = "<select id=\"ddlTstMethod_" + YS_POTestItemCurrentID + "\" class = \"ddlTestMethod\">" + SetCollectionForTestMethodDdl(GetTestMethod()) + "</select>";
this.rownumber = YS_POTestItemCurrentID.toString();
this.Tag = 1;
this.Edit = "<a style="\"text-decoration:" mode="hold" /> this.Delete = "<a style="\"text-decoration:" mode="hold" />}
function SetCollectionForDdl() {
var datacol = GetQualityTest();
var s = '<option value="0" selected="selected">...Select...</option>';
for (var i = 0; i < datacol.length; i++) {
s += '<option value="' + datacol[i].id + '">' + datacol[i].TestName + '</option>';
}
return s;
}
function GetQualityTest() {
if (SET_QualityTestCollection.length == 0) {
$.post("/YS_PO/GetQualityTest", { },
function (data, textStatus) {
if (textStatus == "success") {
SET_QualityTestCollection = data;
}
},"json");
}
return SET_QualityTestCollection;
}
//controller
public ActionResult GetQualityTest()
{
try
{
Bll.QualityTestListinfo qualityTestListinfo = new Bll.QualityTestListinfo();
return Json(qualityTestListinfo.GetDatas(), JsonRequestBehavior.AllowGet);
}
推荐答案
这篇关于Json $ .post或.ajax或.getJSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!