How to query database through javascripts

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Jun 2008
Posts: 21
Reputation: gargg321 is an unknown quantity at this point 
Solved Threads: 0
gargg321 gargg321 is offline Offline
Newbie Poster

How to query database through javascripts

 
0
  #1
Jul 17th, 2008
Hi,

I don't know much about javascripts. I am preparing a module in PHP in which I have to validate data entered by a user through javascripts. Now there is a field in which I have ensure that the value entered by the user already resides in the database. How could I achieve this?
Commitment is what transforms a promise into reality. It is the words that speak boldly of your intentions. And the actions which speak louder than the words. It is making the time when there is none. Commitment is the stuff character is made of; the power to change the face of things. It is the daily triumph of integrity over skepticism.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 3
Reputation: davonz is an unknown quantity at this point 
Solved Threads: 0
davonz davonz is offline Offline
Newbie Poster

Re: How to query database through javascripts

 
0
  #2
Jul 17th, 2008
First you have to make a script in PHP to query the database with the value passed from the script below and then give an output in the script by using either print or echo. In the page that you want to pass the value back to the script you need to add the following....
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script language="JavaScript1.2" type="text/javascript">
  2. function makeRequest(url) {
  3. var httpRequest;
  4.  
  5. if (window.XMLHttpRequest) { // Mozilla, Safari, ...
  6. httpRequest = new XMLHttpRequest();
  7. if (httpRequest.overrideMimeType) {
  8. httpRequest.overrideMimeType('text/xml');
  9. }
  10. }
  11. else if (window.ActiveXObject) { // IE
  12. try {
  13. httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
  14. }
  15. catch (e) {
  16. try {
  17. httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
  18. }
  19. catch (e) {}
  20. }
  21. }
  22.  
  23. if (!httpRequest) {
  24. alert('Giving up :( Cannot create an XMLHTTP instance');
  25. return false;
  26. }
  27.  
  28. httpRequest.onreadystatechange = function() { alertContents(httpRequest); };
  29. httpRequest.open('GET', url, true);
  30. httpRequest.send('');
  31.  
  32. }
  33.  
  34. // Function to deal with returned request
  35. function alertContents(httpRequest) {
  36. if (httpRequest.readyState == 4) {
  37. if (httpRequest.status == 200) {
  38. changeText(httpRequest.responseText);
  39. //alert(httpRequest.responseText);
  40. } else {
  41. alert('There was a problem with the request. '+httpRequest.status);
  42. }
  43. }
  44. }
  45.  
  46. Then with is in the page you only have to make your own function in JS to deal with the reply back from your script on the webserver.
  47.  
  48. function changeText(){
  49. // This is were you put your script to handel if it is the same or not.
  50. }
  51. </script>
Last edited by Tekmaven; Jul 17th, 2008 at 1:33 pm. Reason: Code tags
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the JavaScript / DHTML / AJAX Forum


Views: 707 | Replies: 1
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC