第一次使用Ajax调用在加载事件上给出了完美的结果,但是当我使用Element的单击事件(Recall)调用它时,它将给出响应:文本空白,状态代码:200 OK。
var url = window.location.href;
var customerId = 1;
var OrderBy = 0;
if (url.indexOf('?' + paramCategoryId + '=') != -1) {
var categoryId = parseInt(decodeURIComponent(window.location.search.match(/(\?|&)categoryId\=([^&]*)/)[2]));
if (categoryId > 0) {
GetProductsByCategory(customerId, categoryId, OrderBy); // onLoad Ajax Call
$("ul.sorting li:not(:eq(0)) > a").on('click', function() { // On Element Click Event
OrderBy = $(this).parent('li').attr('Id');
console.log(OrderBy);
GetProductsByCategory(customerId, categoryId, OrderBy);
});
}
}
function GetProductsByCategory(customerId, categoryId, OrderBy) {
$.ajax({
type: "POST",
dataType: 'json',
contentType: "application/json; charset=utf-8",
url: url,
data: '{"customerId":"' + customerId + '","categoryId":"' + categoryId + '","command":{"PageSize":"8","PageNumber":"1","OrderBy":"8"}}',
cache: true,
async: true,
complete: function(data) {
if (data == "undefined") {
targetElement.html(content);
return;
}
var resData = JSON.parse(data);
var categoryResult = resData.CategoryResult;
BindProductsByDisplayMode(CallType.Category, viewType, targetElement, categoryResult);
},
error: function(xhr, textStatus, error) {
targetElement.html(content);
}
});
}
在第二次呼叫时,仅更改了发布请求参数OrderBy
。默认OrderBy = 0 ;
但是当我调用Second Time时,它会在
var resData = JSON.parse(data); => 'undefined '