我正在以这种方式发出 AJAX get 请求
$(document).on("click", ".topp", function ()
{
var id_attr_val = $(this).attr("id");
alert(id_attr_val);
$.ajax({
type: 'GET',
url: 'http://hostip:8080/OrderSnacks/oms/toppings',
jsonpCallback: 'jsonCallback',
dataType: 'jsonp',
data : "topping="+id_attr_val+"",
jsonp: false,
success: function (response) {
console.log(response);
},
error: function (e) {
$("#divResult").html("WebSerivce unreachable");
}
});
});
警报值显示为59,但是当我在控制台中观察时,它以这种方式进行调用
http://hostip:8080/OrderSnacks/oms/toppings?topping=59&_=1402670107061
你能告诉我如何发送 59 ,而不是那些额外的字符吗?
最佳答案
要“删除”&_=1402670107061
部分,您必须在 ajax
请求中设置以下内容:
cache: true,
而且,是的,您仍然可以使用数据:{topping: id_attr_val },
。
cache (default: true, false for dataType 'script' and 'jsonp') Type: Boolean If set to false, it will force requested pages not to be cached by the browser. Note: Setting cache to false will only work correctly with HEAD and GET requests. It works by appending "_={timestamp}" to the GET parameters. The parameter is not needed for other types of requests, except in IE8 when a POST is made to a URL that has already been requested by a GET.
关于jquery - 如何使用AJAX get请求正确传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24207914/