| | |
sending more than the value through ajax
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Apr 2009
Posts: 82
Reputation:
Solved Threads: 5
ok so i am an avid php developer and i am starting to get into ajax so i can keep file sizes and code down to a minimum.
i am looking in the w3schools ajax examples but i am a little lost at how to send through a variable to the page i am using to process.
what i would like to do is send through an id that is being recalled from the database to tell it what to save over.
any help would be very helpful. thanks in advance
ajax
html form
i am looking in the w3schools ajax examples but i am a little lost at how to send through a variable to the page i am using to process.
what i would like to do is send through an id that is being recalled from the database to tell it what to save over.
any help would be very helpful. thanks in advance
ajax
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
function action() { var xmlhttp; if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if(xmlhttp.readyState==4) { document.myForm.time.value=xmlhttp.responseText; } } xmlhttp.open("POST","action.php",true); xmlhttp.send(null); }
html form
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<form action="#" method="post"> <button name="save" type="submit" value="Save" onclick="action();">Save</button> <input type="text" name="address" /> </form>
•
•
Join Date: May 2008
Posts: 254
Reputation:
Solved Threads: 20
1
#2 31 Days Ago
•
•
•
•
ok so i am an avid php developer and i am starting to get into ajax so i can keep file sizes and code down to a minimum.
i am looking in the w3schools ajax examples but i am a little lost at how to send through a variable to the page i am using to process.
what i would like to do is send through an id that is being recalled from the database to tell it what to save over.
any help would be very helpful. thanks in advance
ajax
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
function action() { var xmlhttp; if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if(xmlhttp.readyState==4) { document.myForm.time.value=xmlhttp.responseText; } } xmlhttp.open("POST","action.php",true); xmlhttp.send(null); }
html form
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<form action="#" method="post"> <button name="save" type="submit" value="Save" onclick="action();">Save</button> <input type="text" name="address" /> </form>
The easiest way to send data to your server from the form is using _GET variables
You can take the variables from your form and add them to your string like this
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
function action() { var xmlhttp; if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if(xmlhttp.readyState==4) { document.myForm.time.value=xmlhttp.responseText; } } var textfielddata = document.getElementByID('a_field').value; xmlhttp.open("GET","action.php?Value="+textfielddata); xmlhttp.send(null); }
And this would be your new HTML
html Syntax (Toggle Plain Text)
<form action="#" method="post"> <input id="a_field" name='SomeField' type='text' /> <button name="save" type="submit" value="Save" onclick="action();">Save</button> <input type="text" name="address" /> </form>
My Blog, Life and everything that matters to me - SamRudge.co.uk
2x Macbook Pro's, 1x Mac Pro, 1x iMac, 2x Macbook's running Fedora linux - In conclusion, I hate windows =)
2x Macbook Pro's, 1x Mac Pro, 1x iMac, 2x Macbook's running Fedora linux - In conclusion, I hate windows =)
•
•
Join Date: Apr 2009
Posts: 82
Reputation:
Solved Threads: 5
0
#3 30 Days Ago
alright. but will the address field get sent through to the php file or will i have to build in a var to send it over?
Also the id (which is a mysql row id) that i would like to send through doesn't need to be shown in a input field, and the row id is not going to be the same through out. it will be different based upon the file there looking at.
thanks
Also the id (which is a mysql row id) that i would like to send through doesn't need to be shown in a input field, and the row id is not going to be the same through out. it will be different based upon the file there looking at.
thanks
•
•
Join Date: May 2008
Posts: 254
Reputation:
Solved Threads: 20
0
#4 30 Days Ago
The request URL would have _GET varaibles in, just create the file action.php with the contents
and view the output in Firebug (XHTML requests section)
php Syntax (Toggle Plain Text)
<?php print_r($_GET); ?>
My Blog, Life and everything that matters to me - SamRudge.co.uk
2x Macbook Pro's, 1x Mac Pro, 1x iMac, 2x Macbook's running Fedora linux - In conclusion, I hate windows =)
2x Macbook Pro's, 1x Mac Pro, 1x iMac, 2x Macbook's running Fedora linux - In conclusion, I hate windows =)
•
•
Join Date: May 2008
Posts: 254
Reputation:
Solved Threads: 20
0
#5 30 Days Ago
This is a good tutorial on Advanced AJAX with MySQL
http://www.tizag.com/ajaxTutorial/aj...l-database.php
http://www.tizag.com/ajaxTutorial/aj...l-database.php
My Blog, Life and everything that matters to me - SamRudge.co.uk
2x Macbook Pro's, 1x Mac Pro, 1x iMac, 2x Macbook's running Fedora linux - In conclusion, I hate windows =)
2x Macbook Pro's, 1x Mac Pro, 1x iMac, 2x Macbook's running Fedora linux - In conclusion, I hate windows =)
![]() |
Similar Threads
- sending ajax response form struts2 action class (JavaScript / DHTML / AJAX)
- AJAX in IE malfunction (JavaScript / DHTML / AJAX)
- Keeping Paragraphs using TextArea with AJAX (PHP)
- Ajax Contact Form Help Please (JavaScript / DHTML / AJAX)
- Why do my ajax requests get reposted? (JavaScript / DHTML / AJAX)
- problem in saving unicode using ajax (JavaScript / DHTML / AJAX)
- Client Side < -- > Server Side (ASP)
- Ajax Question (ASP.NET)
- AJAX : Am i right with the concept? (JavaScript / DHTML / AJAX)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: AJAX comment form
- Next Thread: conflicting javascript - clock/time and random background
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate array automatically beta box browser calendar captcha captchaformproblem cart close codes column css date debugger decimal dependent design dom download element embed enter error events firefox focus form frameworks getselection google gwt gxt hiddenvalue highlightedword hint html htmlform ie7 iframe image() index java javascript javascripthelp2020 jawascriptruntimeerror jquery jsp libcurl listbox maps masterpage media menu microsoft mimic mp4 onerror onmouseover paypal php player position post problem programming prototype rating redirect regex safari scale scriptlets search security select software sql starrating synchronous text textarea toggle unicode validation variables w3c webservice website window windowofwords windowsxp xml





