473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

javascript/ajax to mysql db

anfetienne
424 256MB
could anyone tell me the mthod to use javascript/ajax to post to a sql database? or could someone point me to a tutorial?
Apr 27 '09
61 3707
anfetienne
424 256MB
ok will do a test and let you know the results
May 12 '09 #51
anfetienne
424 256MB
ok will do a test and let you know the results
May 12 '09 #52
anfetienne
424 256MB
i can't get this to work on submit.....

how many functions can i have on one action?
Jun 7 '09 #53
acoder
16,027 Expert Mod 8TB
As many as you want; you must be returning from one of the functions. Post your code.
Jun 7 '09 #54
anfetienne
424 256MB
its the same code as what i posted earlier there is no change.....id just like to know how many functions i can run in a onclick and how.

do i seperate with commas? eg onclick="func1 , func2"
Jun 7 '09 #55
Markus
6,050 Expert 4TB
@anfetienne
You separate them, like you would normal statements in the language, i.e. with semi-colons.

Expand|Select|Wrap|Line Numbers
  1. <a href="#" onclick="alert('hi'); func1(); func2(); return false;">...</a>
  2.  
Jun 7 '09 #56
anfetienne
424 256MB
is it possible to do the same using onclick within a form? sorry, i should of phrased myself properly before
Jun 7 '09 #57
Markus
6,050 Expert 4TB
@anfetienne
It's possible with any element. Learn by trying, anfetienne. ;)
Jun 8 '09 #58
anfetienne
424 256MB
lol i know the saying.....just needed to know if it was possible

thanks for the help
Jun 8 '09 #59
anfetienne
424 256MB
I've tested this and it does not work....i have tried using onsubmit, onclick, onmousedown, onmouseup and it still doesn't do anything.

i.e. onsubmit="makeRequest('data.php')"

here is my coding....am i doing something incorrectly?

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" language="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.                 // See note below about this line
  10.             }
  11.         } 
  12.         else if (window.ActiveXObject) { // IE
  13.             try {
  14.                 httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
  15.             } 
  16.             catch (e) {
  17.                 try {
  18.                     httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
  19.                 } 
  20.                 catch (e) {}
  21.             }
  22.         }
  23.  
  24.         if (!httpRequest) {
  25.             alert('Giving up :( Cannot create an XMLHTTP instance');
  26.             return false;
  27.         }
  28.  
  29.         //enter var details for fields here
  30.         var urlparams = "first_name=" + encodeURIComponent(document.getElementById("first_name").value);
  31.         urlparams += "&last_name=" + encodeURIComponent(document.getElementById("last_name").value);
  32.         urlparams += "&address1=" + encodeURIComponent(document.getElementById("address1").value);
  33.         urlparams += "&address2=" + encodeURIComponent(document.getElementById("address2").value);
  34.         urlparams += "&city=" + encodeURIComponent(document.getElementById("city").value);
  35.         urlparams += "&state=" + encodeURIComponent(document.getElementById("state").value);
  36.         urlparams += "&zip=" + encodeURIComponent(document.getElementById("zip").value);
  37.         urlparams += "&os0=" + encodeURIComponent(document.getElementById("os0").value);
  38.         urlparams += "&email=" + encodeURIComponent(document.getElementById("email").value);
  39.  
  40.  
  41.         httpRequest.onreadystatechange = function() { alertContents(httpRequest); };
  42.         httpRequest.open('POST', url, true);
  43.         httpRequest.send('urlparams');
  44.  
  45.     }
  46.  
  47.     function alertContents(httpRequest) {
  48.  
  49.         if (httpRequest.readyState == 4) {
  50.             if (httpRequest.status == 200) {
  51.                 alert(httpRequest.responseText);
  52.             } else {
  53.                 alert('There was a problem with the request.');
  54.             }
  55.         }
  56.  
  57.     }
  58. </script>
  59.  
Jun 15 '09 #60
anfetienne
424 256MB
hi, i have solved this problem myself.....

the best way to do it is to make your file tht saves data to a DB and then use this java code to load a 2nd page.

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. <!--
  3. function dbSubmit(f)
  4. {
  5.     // submit to action in form
  6.     f.submit();
  7.  
  8.     // set second action and submit
  9.     f.target="_self";
  10.     f.action="data.php";
  11.     f.submit();
  12.     return false;
  13. }
  14. //-->
  15. </script>
  16.  
then on your form just add onsubmit="dbSubmit(this)"
Jun 15 '09 #61
acoder
16,027 Expert Mod 8TB
Line 43 should have been:
Expand|Select|Wrap|Line Numbers
  1. httpRequest.send(urlparams);
i.e. urlparams (the variable) instead of 'urlparams' (the string).
Jun 15 '09 #62

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: KDCinfo | last post by:
Although I'm making an ajax call, this is really a javascript question (although it could be even more of an HTML or DOM question... not exactly sure) I'm doing an ajax call to a remote php...
0
by: Free Ebooks | last post by:
81 AJAX and 24 JavaScript Ebooks Here are some of the AJAX topics and areas covered by these ebooks: Rails and AJAX Building Ajax Web Applications Creating Ajax Web Pages Ajax Patterns Ajax...
3
by: SM | last post by:
Hello, Im trying to access elements in my XML file using the JavaScript DOM but i'm not sure how. I use AJAX to access the XML and then use the responseXML property to access the XML file data. I...
2
by: Nathan Sokalski | last post by:
I am moving my website from my machine to my webhost, and need some help with what extra files I need to include due to the fact that I used AJAX in my site. Everything on the site is obviously...
10
by: paulie | last post by:
Hi, I have been experiencing an issue when trying to use AJAX to reload a DIV area using a timer of 2000ms, which contains a html page with another DIV and javascript. Scenario -------------...
1
by: jmohan | last post by:
Dear Sir/Madam, I develop a website in asp.net with c#. And also, I develop a toolbar in the toolbar studio separately. Aim of the Website: Enabling the visitors to become a member of our...
3
by: jarremw | last post by:
hello all, what i have is a modal popup control extender, i have an ajax script that saves the value of the two textboxes that are in the popup, what i am needing is a way to insert those values into...
84
by: Patient Guy | last post by:
Which is the better approach in working with Javascript? 1. Server side processing: Web server gets form input, runs it into the Javascript module, and PHP collects the output for document prep....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.