简体   繁体   中英

Use a cookie value in a getJson call

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

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) {});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM