[英]Second sequential ajax call response not coming into its success function
I have made two sequential ajax call successfully but the response of second Ajax call from controller is not coming into the respective Ajax success function. 我已经成功进行了两个连续的Ajax调用,但是来自控制器的第二个Ajax调用的响应未进入相应的Ajax成功函数。
Ajax Function Ajax功能
$(document).on("click", "#AddTempStock", function () {
var formData = $("#StockItemEntryForm").serialize();
var prodId = $("#addMoreStock").data("prod-id");
$.ajax({
type: 'POST',
url: '../StockTracker/PersistTempStockItem?prodId=' + prodId,
data: formData,
success: function (data) {
var msg = '' + data + '';
if (data != null) {
if (data == 'SUCCESS')
{ // Hiding Popup
$('#GenericPopup').modal('hide');
msg = 'Stock against ' + prodId + ' saved successfully.';
}
// showing message
Messenger().post({
message: msg,
type: 'error',
showCloseButton: true
});
}
},
complete: function (data1)
{
//Showing temporarily Added stock in StockTracker Homepage
$.ajax({
type: 'GET',
url: '../StockTracker/GetTempStockView',
data: { "UserName": '@user', "SeasonYear": '@Season', "Company": '@CompName' },
Below piece of code is not executing. 下面的代码未执行。 ActionMethod is called in controller and returning.
在控制器中调用ActionMethod并返回。
success: function (data1) {
if (data1 != null) {
$('.temp-added-stock').html(data1);
}
}
});
}
});
});
Thanks everyone for suggesting the different ways 感谢大家提出不同的建议
When I inspected the network tab in developer tools, I found out that there was an error(with status code 500) mentioned there with respect to my response url. 当我检查开发人员工具中的“网络”标签时,发现响应URL出现了一个错误(状态码为500)。
Controller Code 控制器代码
[HttpGet]
public ActionResult GetTempStockView(string UserName, string SeasonYear, string Company)
{
TempStockItem temp = new TempStockItem();
DataTable dt = temp.GetTempStockItems(UserName, Company, SeasonYear);
temp.SetTempStockItems(dt);
return PartialView("_TempStockView",temp);
}
Actually there was an error in accessing the attributes of the model in the _TempStockView. 实际上,在_TempStockView中访问模型的属性时出错。 After correction the code run as expected.
更正后,代码将按预期运行。 Below is the code which was corrected
以下是已更正的代码
<img class="thumbnail img-rounded" id="@s.StockProduct.prodid" src="@Models.util.GetImgListFromDB(s.StockProduct.prodid)[0].img" width="70" height="70" style=" margin-bottom: 0px;" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.