Search code examples
jqueryajaxgetjson

AJAX and JSP , $getJSON


So im really having difficulties in understanding the parameters of $.getJSON(), Im currently in my OJT, and there is a AJAX request parameter that I cant figure out.

$.getJSON(jspGetElems, {elem: $(this).val()}).done(function(result){
        //console.log('result',result);
    });

what does the " {elem: $(this).val()} " actually mean?


Solution

  • jQuery.getJSON() has 3 parameter url,data and success. here, in your question elem: $(this).val() is data. You can pass multiple data to server like

    {
      "one": "Singular sensation",
      "two": "Beady little eyes",
      "three": "Little birds pitch by my doorstep"
    }
    

    Try example.

    $.getJSON( "https://jsonplaceholder.typicode.com/posts",{ userId: 1 } ) 
                .done(function(result){ console.log('result',result); });