【发布时间】:2014-01-30 11:39:24
【问题描述】:
当将类型更改为 GET 时,我很难使用 JQuery Ajax 函数通过 post 变量发送。
代码
function loadAttributes() {
var selectedValues = [];
var presentValues = [];
$('#attrplaceholder div').each(function(){
if (typeof $(this).data('attrid') !== 'undefined')
{
presentValues.push($(this).data('attrid'));
}
});
$("#categories :selected").each(function(){
selectedValues.push($(this).val());
});
jQuery.ajax({
url: 'backend.php?r=products/setProductAttributes',
type: "POST",
dataType:"html",
contentType: 'text/html; charset=utf-8',
data: {ids: selectedValues,presentids: presentValues},
success: function(json){
alert(json)
if(json!='[]'){
var obj = eval ("(" + json + ")");
if(obj.json !== 'undefined'){
$.each(obj.json, function(k, v) {
if(k==='views'){
$("#attrplaceholder").append(v);
}
if(k==='rem'){
var remvals = v.toString().split(",");
for(i=0;i<remvals.length;i++){
$("#attrgrp_"+remvals[i]).remove();
}
}
});
}
}
}
});
return false;
}
loadAttributes()
$("#categories").on("change",function(){
loadAttributes()
});
任何指针都会有所帮助,我尝试使用 contentTypes 但仍然没有运气
【问题讨论】:
-
如果您使用 Firebug 或 Chrome 开发工具,您能否检查网络调用并查看您的 AJAX 调用是否包含请求负载中的数据?
-
添加
error回调函数,并记录textStatus -
@DavidHoerster - 请求负载发送以下数据 ids%5B%5D=6&ids%5B%5D=16&ids%5B%5D=13 ,因此正在发送数据
标签: jquery