Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
509 views
in Technique[技术] by (71.8m points)

ajax - How to send parameters with jquery $.get()

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

here's my function:

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

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

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

I also tried:

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

which doesn't work either.

Can you please help me?

EDIT:

also tried

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

Still getting the same result.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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) {
    ...
});

as it would send the same GET request.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...