How to send parameters with jquery $.get()

前端 未结 4 2062
粉色の甜心
粉色の甜心 2020-12-02 22:54

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

here\'s my function:

$(function() {
    var availableProductNames;
    $.get(\"manag         


        
相关标签:
4条回答
  • 2020-12-02 23:09

    I got this working : -

    $.get('api.php', 'client=mikescafe', function(data) {
    ...
    });
    

    It sends via get the string ?client=mikescafe then collect this variable in api.php, and use it in your mysql statement.

    0 讨论(0)
  • 2020-12-02 23:12

    Try this:

    $.ajax({
        type: 'get',
        url: 'manageproducts.do',
        data: 'option=1',
        success: function(data) {
    
            availableProductNames = data.split(",");
    
            alert(availableProductNames);
    
        }
    });
    

    Also You have a few errors in your sample code, not sure if that was causing the error or it was just a typo upon entering the question.

    0 讨论(0)
  • 2020-12-02 23:17

    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.

    0 讨论(0)
  • 2020-12-02 23:18

    This is what worked for me:

    $.get({
        method: 'GET',
        url: 'api.php',
        headers: {
            'Content-Type': 'application/json',
        },
        // query parameters go under "data" as an Object
        data: {
            client: 'mikescafe'
        }
    });
    

    will make a REST/AJAX call - > GET http://localhost:3000/api.php?client=mikescafe

    Good Luck.

    0 讨论(0)
提交回复
热议问题