[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details

pass variable to php script using ajax in a html form using post method

Asked by solohayuno in Asynchronous Javascript and XML (AJAX), HTMLkit

Tags: ajax php variable form post

need to pass a variable to hello.php script
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
<!--Ajax file-->
<script language="JavaScript"> 
        function createInstance()
        {
        var req = null;
                if (window.XMLHttpRequest)
                {
                        req = new XMLHttpRequest();
                }
                else if (window.ActiveXObject)
                {
                        try {
                                req = new ActiveXObject("Msxml2.XMLHTTP");
                        } catch (e)
                        {
                                try {
                                        req = new ActiveXObject("Microsoft.XMLHTTP");
                                } catch (e)
                                {
                                        alert("XHR not created");
                                }
                        }
                }
        return req;
        };
        function storing(data, element)
        {
                element.innerHTML = data;
        }
 
        function submitForm(element)
        {
                var req =  createInstance();
                req.onreadystatechange = function()
                {
                        if(req.readyState == 4)
                        {
                                if(req.status == 200)
                                {
                                        storing(req.responseText, element);
                                }
                                else
                                {
                                        alert("Error: returned status code " + req.status + " " + req.statusText);
                                }
                        }
                };
                req.open("GET", "hello.php", true);
                req.send(null);
        }
 </script> 
 </head> 
 <body> 
 <FORM name='ajax' method='POST' action=''><INPUT type='button' value='Summit' ONCLICK='submitForm(document.getElementById("storage"))'></FORM> 
</html> 
 
 
//php script on another file
<?php
$Computer= $_POST['Data'];
`echo "$Computer"`
?>
[+][-]09/28/09 12:29 PM, ID: 25442454Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/27/09 10:55 PM, ID: 25680240Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625