未捕获的引用错误:未定义$

时间:2018-12-12 18:33:35

标签: javascript woocommerce

我正在尝试在我的商店中设置一些Cookie,以便能够将正确的信息发送到Admitad Affiliate平台。 我们有以下代码:

<script type="text/javascript">
// name of the cookie that stores the source
// change if you have another name
var cookie_name = 'deduplication_cookie';
// cookie lifetime
var days_to_store = 90;
// expected deduplication_cookie value for Admitad
var deduplication_cookie_value = 'admitad';
// name of GET parameter for deduplication
// change if you have another name
var channel_name = 'deduplication_channel';
// a function to get the source from the GET parameter
getSourceParamFromUri = function () {
var pattern = channel_name + '=([^&]+)';
var re = new RegExp(pattern);
return (re.exec(document.location.search) || [])[1] || '';
};
// a function to get the source from the cookie named cookie_name
getSourceCookie = function () {
var matches = document.cookie.match(new RegExp(
 "(?:^|; )" + cookie_name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + 
"=([^;]*)" 
));
return matches ? decodeURIComponent(matches[1]) : undefined;
};
// a function to set the source in the cookie named cookie_name
setSourceCookie = function () {
 var param = getSourceParamFromUri();
 if (!param) { return; }
 var period = days_to_store * 60 * 60 * 24 * 1000; // in seconds
 var expiresDate = new Date((period) + +new Date);
 var cookieString = cookie_name + '=' + param + '; path=/; expires=' + 
expiresDate.toGMTString();
document.cookie = cookieString;
document.cookie = cookieString + '; domain=.' + location.host;
};
// set cookie
setSourceCookie();
// define a channel for Admitad
if (!getSourceCookie(cookie_name)) {
  ADMITAD.Invoice.broker = 'na';
} else if (getSourceCookie(cookie_name) != deduplication_cookie_value) {
  ADMITAD.Invoice.broker = getSourceCookie(cookie_name);
} else {
  ADMITAD.Invoice.broker = 'adm';
}
</script>

并且我收到此错误:未捕获的参考错误:ADMITAD未定义 我应该如何定义var ADMITAD?在哪里? 希望有人可以帮助我解决这个问题。 非常感谢

0 个答案:

没有答案