Ajax forays
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:
[code lang="javascript"]
var ajax = Ajax.Update('myDiv','test.cfm',{method:'get',params:$('myFormID').serialize(true)});
[/code]
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
[code lang="xml"]
[/code]
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