Using jQuery With APE – change the background-color with PHP
A very quick post in regards to Matijah’s comment on Using jquery With APE. We can easily modify the colorChanger application so we can change the background via PHP. This could be extremely helpful in pushing UI changes to users clients, something I struggle to implement using plain PHP and JavaScript.
Demo
There is two code additions within colorChanger.js;
(inside init())
this.onRaw('bgcolor', this.changeBgColor);
(new function)
changeBgColor: function(color){
if(typeof(color) != "string")
color = color.datas.value;
return $("body").css("background-color", color);
},
And that’s it, we’re good to go! We can call the update via; http://0.ape.ifc0nfig.com/?CONTROL&passw0rd&test&POSTMSG&bgcolor&pink&anticache using the libape-controller (make sure its loaded!). We can then call this URL via PHP with file_get_contents():
< ?php $ape_server = 'http://0.ape.ifc0nfig.com'; file_get_contents($ape_server . '/?CONTROL&passw0rd&test&POSTMSG&bgcolor&pink&anticache'); echo 'Message sent!'; ?>
BAM! The background has changed, try out the demo
Demo
Related posts:
- Using jQuery with APE – an OOP approach with the DUI
- EsenAPE – send and receive SMS in real time using APE, jQuery, PHP and libape_controller
- Using jQuery With APE
- Diving into APE modules and the JSF – creating topics for channels
- Facebook Application – Call of Duty 5 Statistics
9 Responses to “Using jQuery With APE – change the background-color with PHP”
Leave a Reply


Matijah on September 3rd, 2009
Hi Paul,
thanx for the tutorial – it will sure be useful.
However, when I make the call from php, the file_get_contents returns “ERR BAD_PASSWORD”.
I double checked the password in libape-controller matches the password in the php.
And I ran out of ideas…
Paul Price on September 3rd, 2009
Hmm, I’m not too sure on that one.
Try changing the password in bin/controller.conf to passw0rd (password=passw0rd), make sure there is no new lines after and then use my request string. The second parameter is the password. I believe it is case-sensitive.
Matijah on September 3rd, 2009
Thanx for mentioning the bin/controller.conf – I completley overlooked this file and was managing the password elsewhere.
Now it works like a charm
iamdrich on November 16th, 2009
Here’s an example session of how this works in python instead of php:
>>> import urllib
>>> f = urllib.urlopen(‘http://0.ape.ape-test.local:6969/?CONTROL&testpwd&test&POSTMSG&bgcolor&pink&anticache‘)
>>> f.read()
‘OK POSTED’
davidynamic on January 5th, 2010
I was wondering why you use APE.Client.prototype
Is that an old specification. Can it be used with the newest release.
Paul Price on January 5th, 2010
Hi davidynamic, not at all. APE.Client.prototype is the same as APE.Client but the .prototype property is used so we can edit it (add methods, etc) which isn’t shown here. It is exactly the same and should work without the .prototype
http://www.packtpub.com/article/using-prototype-property-in-javascript
davidynamic on January 6th, 2010
ok. got it now, Thanks
Paul's Blog » Introducing PubNub – the new cloud-hosted service for real-time messaging on January 9th, 2011
[...] get stuck right in with some code examples. We’re going to re-create this post using PubNub but with a C# client, here’s the [...]
migarcia on February 3rd, 2011
Hello
A good job, with your permission I will leave a link LasFiguritas.com
Sorry for the text-translation of Google