Pass a parameter from client-side to server side and get result

I knows it sounds basic but I can’t seem to get it right. I’m trying to get a data from the API but it needs a parameter in order to obtain the data. How can I pass the parameter and get the result which is a JSON array

$(function() {

	var proxy       = '';
	var endpoint    = 'account/';
	var rt          = 'GET';
	var url         = proxy+'?endpoint='+endpoint+'&rt='+rt;
    var param       = {
        'lastsyncdate' : '2016-12-06'

	$.get(url, function(param) {


You’re actually already sending parameters, namely endpoint and rt. ;-) When sending a GET request, the query string is the only way to pass along data; and if you pass a data object to $.GET as an argument, it will be converted to a query string as well. So these both calls are equivalent:

const proxy = ''

const params = {
  endpoint: 'account/',
  rt: 'GET',
  lastsyndicate: '2016-12-06'

const url = proxy 
  + '?endpoint=' + params.endpoint
  + '&rt=' + params.rt 
  + '&lastsyndicate=' + params.lastysndicate

$.get(url, function (data) {

$.get(proxy, params, function (data) {

Not sure if a mixup works as well though. FWIW, I think the latter approach is much nicer as it avoids messing with string literals.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.