我正在开发一个项目的页面,该页面试图通过按钮(有多个)id标签分配特定值来创建ajax请求。这有效;该值被成功传递,每次点击触发ajax调用。AJAX中的动态变化变量获取请求
当我尝试使用不同的按钮再次呼叫同一页面时,将重新分配变量,但发送的GET请求保持不变。
我如何通过一个新的变量(在这种情况下,ID)传递到GET请求?
function someAJAX(target) {
var trigger = [target.attr('id')];
console.log[trigger];
$.ajax({
// The URL for the request
url: "onyxiaMenus/menuBase.php",
// The data to send (will be converted to a query string)
data: {
//class: target.attr("class"),
tableCall: true,
sort: trigger,
sortOrder: 'DESC',
},
// Whether this is a POST or GET request
type: "GET",
// The type of data we expect back
//The available data types are text, html, xml, json, jsonp, and script.
dataType: "html",
// Code to run if the request succeeds;
// the response is passed to the function
success: function (data) {
console.log("AJAX success!");
$('#prop').replaceWith(data);
}
,
// Code to run if the request fails; the raw request and
// status codes are passed to the function
error: function (xhr, status, errorThrown) {
console.log("Sorry, there was a problem!");
console.log("Error: " + errorThrown);
console.log("Status: " + status);
console.dir(xhr);
}
,
// Code to run regardless of success or failure
complete: function (xhr, status) {
console.log("The request is complete!");
$('#view').prepend(xhr);
}
});
}
$(document).ready(function() {
$(".sort").on("click", function (e) {
//e.stopPropagation();
//e.preventDefault();
target = $(this);
//console.log(target.attr("class"));
console.log(target.attr("id"));
/* ADD CHILDREN TO ELEMENT*/
if (target.hasClass('asc')) {
target.removeClass('asc')
} else {
target.addClass('asc')
}
/* MANAGE CLASS ADD/REMOVE FOR TARGET AND SIBLINGS */
if (target.hasClass('btn-primary')) {
} else {
target.addClass('btn-primary')
}
someAJAX(target);
target.siblings().removeClass('btn-primary');
})
});
触发器在ajax函数的第二行中定义。实际的通话正在工作,但只有第一通电话。 –
啊,我错过了......究竟是什么意思,它不是第二次工作。它在做什么?你是否在控制台中发现错误?同样,目标是同一个元素的两次函数被调用,如果它是只是将相同的确切的调用..这将解释为什么什么都没有发生.. –