jquery - 如何使用AJAX get请求正确传递参数

标签 jquery

我正在以这种方式发出 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/

相关文章:

Javascript if 语句忽略 jQuery $(this)

javascript - Jquery关于属性操作的问题

c# - 如何在 iframe 中加载网页

javascript - jQuery/JavaScript 函数不更新文本框

javascript - 启用自动完成的输入类型密码。 val() 变成空白

JavaScript 套接字连接

javascript - JQuery - 在加载并直接转到带有 anchor 的 URL 时获取偏移量

javascript - 使用按钮单击 jQuery 触发 Google 翻译

javascript - javascript模式的正则表达式

javascript - 如何在单选按钮的 'checked' 属性上调用 javascript 函数?