18 Mar 2008
There are many ways to make the ajax request. This probably isn't the best, but it's the one I am most comfortable using. This example requires that you have the json extension for php. It can be done without it, but json makes the data transfer from php to javascript much cleaner.
testAjax.tpl:
{zoop_file_js files="ajax/dojo/dojo.js"}
<form id="main_form" name="main_form" method="POST" action="{$VIRTUAL_URL}" enctype="multipart/form-data">
<script type="text/javascript">
{literal}
function submitForm(action)
{
if(window.verifyFormFunction)
{
if (!verifyFormFunction(action))
return false;
}
document.main_form.actionField.value = inAction;
document.main_form.onSubmit();
document.main_form.submit();
}
function checkUserName()
{
dojo.io.bind({
{/literal}
url: "{$SCRIPT_URL}/checkUserName",
{*url: "{$zoneUrl}/checkUserName",*}
{literal}
mimetype: 'text/json',
method: 'post',
formNode: document.main_form,
handler: function(type, data, e){handleUsernameData(data);}
});
}
var usernameOk = false;
function handleUsernameData(data)
{
if(data.exists == true)
{
div = document.getElementById('usernameExists');
div.style.display = '';
}
if(data.bad == true)
{
div = document.getElementById('usernameBad');
div.style.display = '';
}
if(data.ok == true)
{
div = document.getElementById('usernameExists');
div.style.display = 'none';
div = document.getElementById('usernameBad');
div.style.display = 'none';
usernameOk = true;
}
}
function verifyFormFunction(action)
{
if(action == 'submit' && !usernameOk)
{
alert('Please enter a valid username.');
return false;
}
return true;
}
{/literal}
</script>
<input type="text" name="username" onBlur="checkUserName();">
<div id="usernameExists" style="color: red; display:none">This username already in use.</div>
<div id="usernameBad" style="color: red; display:none">This username is too short, or contains invalid characters.</div><br/>
<input type="password" name="password"><br/>
<input type="password" name="password2"><br/>
<input type="submit" onclick="submitForm('submit'); return false;">
<input type="hidden" name="actionField" value="default">
</form>zone_default.php:
function pageTestAjax($p)
{
$this->guiDisplay('testAjax.tpl');
}
function postTestAjax($p)
{
//save the user
}
function postCheckUserName($p)
{
$username = getPostText('username');
$answer = array();
if(strlen($username) < 2)
$answer['bad'] = true;
else
$answer['bad'] = false;
if(sql_check("select id from user where username = '$username'"))
$answer['exists'] = true;
else
$answer['exists'] = false;
$answer['ok'] = !$answer['bad'] && !$answer['exists'];
echo json_encode($answer);
}
Header Missing
I also send a header with my JSON data which will help Prototype decode the data automatically. I am not sure it this helps DOJO or not. Just thought I would add this if others needed to know
Bad
The example is not working correctly, fix it. It`s not a good idea to post something witch not working properly.
Look at this : $answer['ok'] = !$answer['bad'] && !answer['exists'];
what is this????????????
Typo
Thank you for pointing out that typo.
The rasmus lerdorf's really
The rasmus lerdorf's really long talk at drupalcon szeged last year make sure to check out the presentation slides for all the gory details. Thanks for sharing the informative post.
Regards.
samson - car ship
This is good site to spent
This is good site to spent time on .I just stumbled upon your informative blog and wanted to say that I have really enjoyed reading your very well written blog posts. I will be your frequent visitor, that’s for sure..
Medical billing || NJ nightlife
thanks
This is a very informative article.I was looking for these things and here I found it.Masterboard I am doing a project and this information is very useful me. If you are interested, but this is my duty to inform you that virtual administrative assistant a very dedicated service and can be applied anywhere you want and get better results.
I enjoyed reading this post
I enjoyed reading this post which is highly informative.I recently came across your blog and have been reading along and the article you have written is very interesting.
mayweather vs ortiz tickets | home lighting ideas
Great Tutorial
This reminds me of the dreadful programing days back in college.Small boat building It still refreshing to see that other don't find it as difficult as I. Cheers & keep the programing alive.
Nice after having been with
Nice after having been with this interesting work. What's really good to know that this issue is also being covered on this site, so thanks for taking the time to discuss this. Julian @ Fleet Tracking
nice blog
I appreciate, lead to I found exactly what I used to be having a look for. You have ended my four day lengthy hunt! God Bless you man. Have a nice day. Christmas countdown
Das Konto testen. Wie
Das Konto testen.
Wie Tagesgeld funktioniert.
Einfach Tagesgeld vergleichen.
Wieso Geldanlagen gefragter werden.
hi
That Mercedes Benz vehicle was already famous as a luxury vehicle a very classy. I think it fair if this car is the right choice.how to get your ex back | yeast infection treatment
I am very happy for finding
I am very happy for finding this another ajax technique example.I will use this in my application. I am sure that your job is clearly identified as a fair game. template website
Youre truly well-informed. I
Youre truly well-informed. I cant believe how much of this I just wasnt aware of. Thank you for bringing more information to this topic for me. Im truly grateful and really impressed.relatiegeschenken
This is really awesome!
Write my essay
Whenever possible, because
Whenever possible, because you gain expertise, do you mind updating your blog post with extra information?Computerhulp
software
I wonder if you could help me with a dll search sequence which could also work attached to a website plugin so any user can have access to it. Could you help me with a code example for my issue? I would appreciate that. Thank you.
A bit hard
Your question is a bit hard for me..maybe someone will help you.
pizza games
Good Infomation
keep up the good job i like your post very much. expect more post from your side. waiting for your post. keep up the good job
http://www.zithromaxgeneric.net
Yes really such a nice
Yes really such a nice tutorials and explanation Web design
Austin Home Builder
The faster the code can run, the better the performance. I think programmers often get caught up using complex algorithms, and that often leads to a slower system. The end user is mainly concerned with reliable performance and a fast pace. If you can accomplish those two factors, then you've created a successful program.Austin Home Builder
outsourcing
It’s always nice when you can not only be informed, but also entertained! I’m sure you had fun writing this article.outsourcing
hello
Fabulous post,This is such a great resource that you are providing us.
qr code maker
The content is very original
The content is very original and interesting. I've got a big pleasure to spend time in your site. Congratulation for your nice work.
free cell phone spy software
Excellent Example. Resources
Excellent Example. Resources like the one you mentioned here is very useful! I will post a link to this page on my blog. I am sure my visitors will find that very useful.
Good examples! Please post
Good examples! Please post more helpful examples so I shall be able to work on php more effectively. Thanks for kind help :)
Brochure Design
This is a great inspiring
This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information.
California DUI Lawyer
AJAX EXAMPLE
I had used several other ways to make an ajax request but all of those failed. This is the only one that I found to be very comfortable and I guess the best among all other examples that I had found. Thank you so much for this. Golf Clubs Second Hand
Web applications have made
Web applications have made huge leaps and bounds in improving user experience thanks to a large number of newly developed technology Ajax.
Jullian @ LED TV deals
Eine Kreditkarte testen. Wie
Eine Kreditkarte testen.
Wie die Kreditkarte verglichen wird.
Wie Kostenlose Kreditkarten gefunden werden.
Ein Konto finden.
Wie man Kreditkarten vergleicht.
Web Design Dubai
OMG! I have to say, your blog needs to be one of the best written blogs that I have learn in a protracted time.What I wouldn't give as a way to put up posts which might be as interesting| as yours. I guess I will have to continue studying yours and pray that someday I will write on a subject with as a lot wisdom as you have! Bravo!! Web Design Dubai
I recently came across your
I recently came across your article and have been reading along. commercial air filters
Thank you for another
Thank you for another essential article. Where else could anyone get that kind of information in such a complete way of writing? I have a presentation incoming week, and I was on the lookout for such information.Waterproofing basement
Thanku for this example..
Really thanks for such article.I am very happy for finding this another ajax technique example.I will use this in my application.This example would be more helpful for the developer.
buy used cars
Hello, I truly enjoyed
Hello, I truly enjoyed reading your post. I found your site from Bing. Will bookmark to return later. Thanks!
Wedding Bands
I am very much interested in
I am very much interested in reading articles. This blog was really an awesome site which I had never found it anywhere. Lots of stuff in this site ! Really helpful for most of them ! baldai
Thanks for enjoying it.
The ZOOP development is great.
lmi pumps
Kala Darshan
Even i like the zoop development too kaftan
It is such an important
It is such an important topic and ignored by so many, even professionals! I thank you for helping to make people more aware of these issues. Home Automation | Gourmet Gift Baskets
Useful information
Useful information shared..Iam very happy to read this article..thanks for giving us nice info.Fantastic walk-through. I appreciate this postFettabbau effektiv
Though you have said that
Though you have said that this wasn't the best example you have but I must try it for me to judge and experience.
GolfSmith
hello
Just bookmarked this link in my browser. I will definitely visit this site later to read some more quality blogs. Thanks. vacation to Disney
This is a very intriguing
This is a very intriguing post, I was looking for this knowledge. Just so you know I located your blog page when I was looking around for blogs like mine, so please check out my site sometime and leave me a comment to let me know what you think.Old Cars For Sale
Haus Haus Haus Haus Haus
Haus
Haus
Haus
Haus
Haus
Nowadays, there is a trend
Nowadays, there is a trend of getting a website designed and developed every other day, however, most of them do not provide the returns, which they could. Yes, you have read it right, a website can provide you immense potential customers on a daily basis if it is a business web portal, and countless visitors,
I would like to voice my
I would like to voice my admiration for your kindness supporting those individuals that really want help with this subject. Your real commitment to getting the message all-around had been particularly interesting and have regularly enabled most people just like me to attain their targets. The important help means a whole lot a person like me and far more to my colleagues. Many thanks; from everyone of us.....
clubmz e-spy
Yes!
What an enjoyable read this turned out to be! It's not too often I find content that impresses me on every level - and this post most certainly did. Reverse Cell Phone Lookup|Pellet Stoves
I think you did an awesome
I think you did an awesome job explaining it. Sure beats having to research it on my own. Thanks
phlebotomy training
I really want to thank yahoo
I really want to thank yahoo search engine who have sent me to this wonderful site. The articles posted on this site are great and amazing. I am glad that I have found this amazing site.
лечение в израиле
Wie eine
Wie eine rechtschutzversicherung aussieht.
Den Privat Rechtsschutz vergleichen.