0

I want to use a getJson call like this"

$.getJSON("cfc/getMember.cfc?method=getUser&returnformat=json&queryFormat=column",{"memberID":userID}, function(res,code)

the userID is stored as a cookie - so I thought I'd simply use:

function checkCookie(){ 
 var userID=getCookie("UID");
}

Now (as I'm sure you cal tell) I'm new to javascript so that might be my problem - but I'm after some advice on how to use a cookie value in the getJSON call.

Thanks!

Simon

Simon
  • 227
  • 2
  • 3
  • 15

1 Answers1

1

Assuming your getCookie() function is already defined and correctly retrieves your cookies, then all you need to do is define the userID before you make the call to $.getJSON:

var userID=getCookie("UID");
$.getJSON("cfc/getMember.cfc?method=getUser&returnformat=json&queryFormat=column", {"memberID":userID}, function(res,code) {});
Calvin
  • 8,697
  • 7
  • 43
  • 51
  • Thanks Calvin - I've got var userID=getCookie("uid"); as part of the check cookie function - are you saying I need to repeat it? Thanks. – Simon Mar 08 '12 at 05:47
  • For how to use jQuery to get cookie: http://stackoverflow.com/questions/1599287/create-read-and-erase-cookies-with-jquery – Dror Mar 08 '12 at 05:48
  • @Simon, no you simply need to declare your `userID` variable before you call the `$.getJSON()` method, so that you're not inserting an undeclared variable as "memberID". – Calvin Mar 08 '12 at 06:01