我有两个复选框,其中包含一些像这样的值:
3
我用这样的Ajax调用得到这些值:
现在,当我回显服务器端(PHP)中的变量时,它显示:
"test"
谁和为什么被"
添加?我该如何删除它们?
我已经尝试过PHP函数preg_replace
和其他东西.
请你帮忙......
您可以使用对象而不是字符串
var data = { hotel_boutique: hotel_boutique, hotel_stars: hotel_stars };
问题是"
在数据字符串中,您也可以尝试
var data = 'hotel_boutique='+hotel_boutique+'&hotel_stars='+hotel_stars;
整体代码可以简化为
jQuery("input[type='checkbox']").change(function () { var data = { hotel_boutique: $('#hotel_boutique:checked').val()||'NULL', hotel_stars: $('#hotel_stars:checked').val()||'NULL' }; jQuery.ajax({ url: "processAjax.php", type: "GET", data: data, cache: false, beforeSend: function () { jQuery("#loading").show(); }, success: function (data, textStatus, XMLHttpRequest) { jQuery("#content").html(data); jQuery("#loading").hide(); }, error: function (MLHttpRequest, textStatus, errorThrown) { alert(errorThrown); } }); });