如何使用 jquery $.get() 发送参数 [英] How to send parameters with jquery $.get()

查看:28
本文介绍了如何使用 jquery $.get() 发送参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行 jquery GET 并且我想发送一个参数.

I'm trying to do a jquery GET and i want to send a parameter.

这是我的功能:

$(function() {
    var availableProductNames;
    $.get("manageproducts.do?option=1", function(data){
        availableProductNames = data.split(",");;
        alert(availableProductNames);
        $("#nameInput").autocomplete({
            source: availableProductNames
        });
    });
});

这似乎不起作用;当我使用 request.getParameter("option");

This doesn't seem to work; i get a null in my servlet when i use request.getParameter("option");

如果我在浏览器中输入链接 http://www.myite.com/manageproducts.do?option=1 效果很好.

If i type the link into the browser http://www.myite.com/manageproducts.do?option=1 it works perfectly.

我也试过:

$.get(
    "manageproducts.do?",
    {option: "1"},
    function(data){}

这也不起作用.

你能帮我吗?

也试过

       $.ajax({
      type: "GET",
      url: "manageproducts.do",
     data: "option=1",
     success: function(msg){
        availableProductNames = msg.split(",");
        alert(availableProductNames);
        $("#nameInput").autocomplete({
        source: availableProductNames
    });   
     }
      });

仍然得到相同的结果.

推荐答案

如果你说它适用于在浏览器中直接访问 manageproducts.do?option=1 那么它应该适用于:

If you say that it works with accessing directly manageproducts.do?option=1 in the browser then it should work with:

$.get('manageproducts.do', { option: '1' }, function(data) {
    ...
});

因为它会发送相同的 GET 请求.

as it would send the same GET request.

这篇关于如何使用 jquery $.get() 发送参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆