Backendless Support
 
Answered

getting URL parameters in js file

Hi,

How can I get the URL parameters when calling a js file saved in web/scripts?

Thanks,

Tal

Leave a Comment

Comments (8)

photo
1

Hi Tal,

Try this:

  1. request.query.PARAMETERNAME

Where PARAMETERNAME is the actual parameter.

Mark

photo
1

this is not working:

  1. var clk = request.query.clk;
  2. var userAcquisitionRedirectsItem = new UserAcquisitionRedirectsItem( { adNetwork : 'archy', appId : 'appId', clickId : clk, country : 'IL', userAdvertisingId : '1234-afjad-test', userIp : '192.168.1.144' });

after this code I see in the table all the values, except for clickId which is empty

photo
1

How do you send the parameter in the URL?

photo
1

Is it a GET or POST request?

photo
1

I'm pasting this url in a browser

photo
1

Well, I just did a simple test and it is working as expected. Here's a URL to try:

https://api.backendless.com/91186007-E09C-8561-FF0E-ADCD410BF400/v1/files/web/scripts/hello.js?test=foo

Here's the source code of the script:

  1. exports.run = function ( request, response )
  2. {
  3. response.send( "value of the test parameter is: " + request.query.test );
  4. };

It seems like the problem would be somewhere in your code.

Regards,

Mark

photo
1

thanks mark, found my error

photo