Archive

Archive for the ‘Javascript’ Category

Ajax forays

March 24th, 2009 No comments

I’ve began playing with Ajax for the first time in the last week. I wanted to load up a page and display it within the current page. So I decided to use an Ajax request to get the page but I also needed to pass in some parameters to this page from a form on the current page. After spending a bit of time messing around trying to convert the parameters and pass them in through the url of the request, Michael Sharman who I work with showed me a nice Prototype function serialize(). This takes in a form element and converts it to a string of parameters e.g. id=4&class=five&test=yes. It can also convert to form to key value pairs but I didn’t need that at the time. I then just called the page like so:

var ajax = Ajax.Update('myDiv','test.cfm',{method:'get',params:$('myFormID').serialize(true)});

This places the content from the ajax request into the div of id ‘myDiv’.
The funny thing is that I had used the request to place the div within a form which was then submitted but the content obtained from the Ajax request doesn’t seem to register with the DOM and didn’t appear when the form was submitted.

So I had

So the div within the form would be filled from the Ajax request but when the form was submitted and the form variable dumped, the div elements wouldn’t show up even though they are inputs, selects etc.
I wonder is there a way to register content got from an Ajax call with the DOM?

Turns out what I was doing was quite stupid idea anyway and was better suited to a CF custom tag so I did that instead but would be interested in the solution.

I was getting a lot of spam on certain WordPress posts in the last couple of weeks. You may remember the problem I was having the stylesheet a few weeks back and my solution was to let unregistered users to post. An unregistered user only needed to enter their username and comment and that was it. Obviously this meant it was vulnerable to spamming and indeed I was moderating about 10 posts a day and marking them as spam. Getting annoyed with having to do this I looked around for free captchas for WordPress and found this site - http://www.protectwebform.com/plugin_wordpress. You need to register which is a bummer but after following the steps it seems to be working nicely after one day, no more spam :)

Categories: Archive Post, Javascript Tags:

Reading RSS Feeds in php and Javascript table sorting

March 24th, 2009 No comments

Hello there,

Been working with SimplePie recently, its an RSS feed reader/parser that works with PHP. So far the results have been really good, it takes only 4 lines to go and fetch an RSS and return it in a friendly format:

$feed = new SimplePie();
$feed->set_cache_duration($cache_time);
$feed->set_feed_url($URL);
$feed->init();

I’ve not seen where the cache is sent yet OR what it actually caches but seems pretty easy.

I started using the JQuery tableSorter utility yesterday also. It is good enough, not as good as I’d like though. I had to manually resize some of the images that are used within the tags as they were leaving too much space which caused the headings to move onto a third line. Also I don’t know if they can use filters yet or if its possible to run ajax on the table. Anyway though getting the table sorter working is pretty straight forward

Get the full release from http://tablesorter.com and place jquery-latest.js, jquery.tablesorter.js in somewhere that can be read by your page(I’m using ColdFusion). Place the following code in your header:






Once done I just made my table:

DATA STUFF
Header 1 Header 2

That worked for me anyways!

Apart from that I’ve gone back onto using Asterisk recently again and will be doing a bit more PHP AGI in the near future so expect to hear some more about that!

Categories: Javascript, PHP Tags: