Got a request to make a quick hack; but this quick hack will be immensely helpful and able to cut like 3 hours of work / employee everyday. Naturally, seeing such huge cost / benefit ratio, I agreed to make it my priority.
The hack is to make pricing become automatic for a client. At the moment, they have to look up a pricing table manually for each order that they received. Even though they’re pretty big, built their own IT system from scratch, they’re still doing this particular topic manually. I can’t believe that their previous developer missed this stuff.
Until I realized the full scope of the job…. suffice to say, it’s complicated enough to scare most programmers. Their pricing scheme almost got no pattern at all, almost fully customized for every client. Yet we can’t afford to just enter the whole thing as it is to the database – it’d be too cumbersome.
The previous developers spent 3 years developing the system, and still managed to avoid this particular bit.
More time would be required to develop the algorithm and proper database schema, than the actual coding itself. Anyway, more to that probably later; one particular thing that I’d like to avoid in this job is the XMLHTTP-request stuff.
Why ? Because I’m too lazy 🙂 too lazy to implement it myself from scratch, and I don’t have the time to use the available implementations (and deal with their quirks/bugs).
I like things as simple and as fast as possible. I think I’m kinda a control freak, yes that explains it.
Anyway, here’s the requirement:
1. Once the staff entered an order into the system, he’ll clink into a link on the form.
This link will fill the textbox next to it with the right price for that order
That’s it. What’s going on behind the curtain is of course much more than that. Here you go :
1. The link actually invokes a JavaScript function called do_ajax()
2. The function will then append a JS element – which actually a PHP script. Thus executing the “AJAX” call
3. The JavaScript function can communicate with the server-side PHP script by way of GET method.
4. The PHP script produced its output as JavaScript code.
As simple as that.
Here are the details:
The HTML form
cn-ajax.js
cn-ajax.php
< ?php // do the calculations here // report the price set_price($total_price); exit; function set_price ($thetotal) { echo "inputtext = document.getElementById('total_charges'); "; echo "inputtext.value = '$thetotal';"; } ?>
It may look complicated at first, but if you think of the cn-ajax.js as a blackbox,
then it became very simple.
NOTE: Another plus is that this form become usable for mobile warriors as well. Sure today’s PDA can do JavaScript – but speedily? Thought so.
This trick moves most of the processing to the server, with as little JavaScript code as possible. Therefore giving the best performance for these audience.
Other advantages are : clean, cross browsers, adherence to standards.
(thanks rendy ak)
Credit goes to PHPit.com for figuring these out.
TIP: Use Firefox while debugging this stuff. Its JavaScript console was a massive help to me.
OK, back to work.
See also the FireBug extension for debugging in Firefox.
nambahin ?? IFRAME jg bisa dipake..
lalu.. cobain prototype deh 😀
walah.. ada yg ilang. mestinya
nambahin tag script ?? IFRAME jg bisa dipake..
Kreatif banget!
Otomatis cross browser, standards compliant and clean. Tapi nanti kalau sering2 dipanggil di_ajax-nya bakal ada banyak ‘tempelan’ element script dong di DOM-nya?
Ups typo, mxd-nya do_ajax()
Hmm.. yet another AJAX-wrapper-library. I easily get lost with enormous amount of such wrapper nowadays (check ajaxpatterns.org and ajaxian.com).
Sooner or later, we will get our hand dirty with XHR. Speaking from my painful experience 🙂
And when the time comes, I agree with Ronny, Firebug is our best friend.
iang – thanks untuk rekomendasinya. btw; <script> dan IFRAME ? mungkin bisa dibagi juga tipsnya 🙂
ak – sepertinya sih begitu, tapi kalau dicek di “view source”, tidak kelihatan (karena browsernya fetch yang aslinya, bukan yang sudah termodifikasi). anyway, yang penting bisa ajax, hoho
andry – yes, I think XHR is inevitable. But if I can avoid using it as long as possible (with help from this little gem), then when I finally need it, the selections are already in a much mature state. I’d rather let others to enjoy the bugs if I can help it 🙂
Mungkin akan kelihatan dengan Firefox DOM inspector, atau plugin view generated source. Tag-tag tidak penting seperti itu nantinya bisa memenuhi memory (meski mungkin tidak terasa langsung).
Mungkin bisa ditambahin attribute id, dan kode JS yang ‘baru dateng’ itu bisa otomatis mencari remove elementnya sendiri?
I’ve used this method before. It’s actually a lot more compatible than I thought it would be. It’s a little slow however, and doesn’t give you any browser history, which is just like the XMLHTTPRequest method. If you want do have history, you need to use the IFRAME method. Not all application would benefit from having history though.
HRsmart provides the full range of Talent Management Software, Employee Performance Management, Applicant Tracking, Learning Management and much more to help organizations of all sizes attract, identify, develop, motivate and retain top performers.
Companies with a defined and technologically-supported talent management strategy have higher retention rates, more productivity and perform at a higher level. Our solutions help you uncover the skills, competencies, motivators and drivers within your existing talent, and enable you to use the information to optimize performance within your organization.
About the Author
Human Resource Software
Learning Management System
Succession Planning
Nice info. This blog has really awesome information about php & ajax. very useful info. Free Blogs are the best source of valuable information & experience of different people, In this way, i can also learn many things by visiting this. People can also share their thoughts, views, pictures, at Free Blogspot as well.
Thank you for your article. The earthquake – the phenomenon of nature and a tragedy for the people. Unfortunately, the earthquake could not stop prematurely. I am sympathetic to those who survived the earthquake.
Ya this is appreciated.Well done for your job.
thank you guy for sharing a good information for us
nice post , keep doing this as well
good works. Thank you very much for this information. I like This site! Thanks!
mmm… that awesome…
This was just the information I was looking for, great resource. Bookmarked.
Thank you very much for this information. I like This site! Thanks!
I will try to use it. Many thanks.
nice info…
regards…
http://www.indrafer.com/
Free Download Software, Web Script, Tips Trick SEO, Cheats, Kaspersky Keys, etc…
yeah, I will use it.
Thanks for the good information above, i am little bit more interested in PHP Development and know about PHP, will back you soon.
Everyone must try this, its really work more than we expect but on the other hand its bit slower that’s the only flaw it has.
I am not much into reading blogs and articles, but somehow I read some articles on your blog and found the information helpful and interesting.
I don’t know If I said it already but …I’m so glad I found this site…Keep up the good work I read a lot of blogs on a daily basis and for the most part, people lack substance but, I just wanted to make a quick comment to say GREAT blog. Thanks, 🙂
A definite great read….
When it comes to obtaining information on the web, nothing beats a blog, where ideas and opinions abound. Blogs make for great reading and and I am pleased to be able to add something of value.
It is nice to see someone so good at blogging. HaHa! I try to spend time on blogs where I am able to learn a lot of new stuff. With this blog, not only the design is great, but so much of the information appears to be interesting and helpful. I have absolutely had a good time here and have walked away with things I did not know before.
There was a time when all information had to be gathered from books. With the advent of the internet, access to information has exploded. This blog is a good example of new information which can be quite helpful in a number of ways. I appreciate people who put up their own blog and present new ideas and comments.
Yesssssssssssssssss….Info yang sangat bermanaat mas . .terima kasih banyak..
, they’re still doing this particular topic manually. I can’t believe that their previous dev
I love PHP ang mysql
he phenomenon of nature and a tragedy for the people. Unfortunately, the earthquake could not stop prematurely. I am sympathetic to those who survived the earthquake.
70-558,70-559,70-561,70-562
THANKS FOR SHARING..
perlunya web komunitas event organizer and indonesia pancen houye
thanks 4 ur great info
Wow!! very interesting info! Thanks for the share!
All the Best!
Great article…ilearn so much by reading it
I am not much into reading blogs and articles, but somehow I read some articles on your blog and found the information helpful and interesting.
Tsani Oke
Koswandy
Devi Kunyai
trims mas…
thanks sobat infonya…
Nice post, very interesting about it…
Terimakasih informasinya..
It was a great post! I loved every word thanks and it helped me with coding and stuff.
Artike yang bagus dan berguna bagi pembaca sekalian, terimakasih.
Siiip… its nice, thanks
Excuse the quality of the shot – I was late to understand it, and had little time to took a shot. If you can not see clearly – Linus Airways and banners are in the middle and the bottom of them.
A nice way to ajaxify without the XmlHttp. We used earlier Iframe to load the content and recieve the document text to do without showing postbacks
the sample is very useful.
Makasih mas peluang bisnis online blakblakan dan top 1 oli sintetik mobil-motor indonesia dan Bejubel Market Place Terbaik Indonesia ya..
Can ajax work without xmlhttp? Looks like possible. I will give a try once i am get back to my workstation.
It is really hard to live without AJAX these days. Jquery is another framework we love to program with.
thanks before
Hmm.. yet another AJAX-wrapper-library. I easily get lost with enormous amount of such wrapper nowadays (check ajaxpatterns.org and ajaxian.com).
Sooner or later, we will get our hand dirty with XHR. Speaking from my painful experience
What beauty is, I know not, though it adheres to many things.
Hey, just thought I’d let you know that there’s something weird going on with your blog theme right now. Like, there are no images and the site looks like something made 15 years ago! You might want to look into it, maybe it’s just a temporary error…
I’ve used this method before. It’s actually a lot more compatible than I thought it would be. It’s a little slow however, and doesn’t give you any browser history, which is just like the XMLHTTPRequest method. If you want do have history, you need to use the IFRAME method. Not all application would benefit from having history though.
I’ve used this method before. It’s actually a lot more compatible than I thought it would be. Nice post.
You find one brilliant solution to the problem. In my career I noticed that good solution is always SIMPLE.
Nice post and appropriate solution.
There are very informative stuff which I looking for, I’ll bookmark this site for further information, such a great job.
Well this is very interesting indeed. Would love to read a little more of this. Great post. Thanks for the heads-up. This blog was very informative and knowledgeable.
Mungkin akan kelihatan dengan Firefox DOM inspector, atau plugin view generated source. Tag-tag tidak penting seperti itu nantinya bisa memenuhi memory (meski mungkin tidak terasa langsung).
This is my fourth time coming by your blog.I just stumbled upon your blog and wanted to say that I have really enjoyed browsing your blog posts.
I vividly remember the stories my grandfather told me about the carnage of the First World War, which people tend to forget was one of the worst massacres in human history.
goes to the nitty-gritty of the patient matter. Your quality basically leaves me seeking to know more. Just so you know, i will instantly pick up your feast to keep up currently with
The information and the aspect were just wonderful. I think that your viewpoint is deep, it’s just well thought out and truly incredible to see someone who knows how to put these thoughts so well. Good job!
Thanks for this informative post. It help me a lot. And it gave mo ideas on how to make more money in marketing business. I hope lots of people visit this site so they can easily learn this informative post.
I loved as much as you will receive carried out right here. The sketch is attractive, your authored subject matter stylish. nonetheless, you command get bought an nervousness over that you
Thanks for the post….I enjoy it!