开发者

Javascript or jQuery fetch a Processingjs variable?

开发者 https://www.devze.com 2023-01-26 20:01 出处:网络
Is it possible to pass a variable from processingjs to Javascript / jQuery for use in AJAX send t开发者_如何学JAVAo serverSure it\'s possible. There are many ways, one of the ways is to attach the var

Is it possible to pass a variable from processingjs to Javascript / jQuery for use in AJAX send t开发者_如何学JAVAo server


Sure it's possible. There are many ways, one of the ways is to attach the variable you wish to pass around to the window object. It's not the only solution and definitely not the most elegant solution, but, it works.

So something like this:

// processingjs code...
window.varIWantToPassAround = "whatever"; 

// jQuery code... 
// as long as you don't redefine the variable "varIWantToPassAround", you can reference it without referencing the window object. IE "window.varIWantToPassAround"
// but I like to be explicit so when I read my code 3 months later and go "where did *that* come from, I can see it is attached to the window object.
$("#unicorn_powerd_div").someFunctionThatGrowsMagicUnicorns(window.varIWantToPassAround);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号