Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Problem in php ajax post value.
Old 12-06-2010, 08:42 PM Problem in php ajax post value.
Novice Talker

Posts: 7
Trades: 0
I want to post value from index.php, then get the value by self without refresh the page. one botton with two values, I want explode them and finally get $namea and $nameb. then use them in other php part.
but when I use echo $name, in the source code, I can see <div id='msg'></div>(html tag), this is not a pure value, so I tried to use strip_tags, but the value lost. it seems the left the ajax pointed div tag, the value also gone.


index.php
PHP Code:
<head>   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   <script language="javascript">   function saveUserInfo() {       var msg = document.getElementById("msg");       var f = document.user_info;       var userName = f.user_name.value;       var url = "value.php";       var postStr   = "user_name="+ userName;       var ajax = false;         if(window.XMLHttpRequest) {           ajax = new XMLHttpRequest();           if (ajax.overrideMimeType) {               ajax.overrideMimeType("text/xml");           }       } else if (window.ActiveXObject) {           try {               ajax = new ActiveXObject("Msxml2.XMLHTTP");           } catch (e) {               try {                   ajax = new ActiveXObject("Microsoft.XMLHTTP");               } catch (e) {               }           }       }         if (!ajax) {           window.alert("wrong");           return false;       }         ajax.open("POST", url, true);       ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");       ajax.send(postStr);       ajax.onreadystatechange = function() {           if (ajax.readyState == 4 && ajax.status == 200) {               var myPhpVariable = ajax.responseText;               msg.innerHTML = myPhpVariable;               // myPhpVariable is now a variable which you can use              alert( myPhpVariable );           }       }   }   </script>   </head>   <body>  <?php  echo $name="<div id='msg'></div>";  $name1=strip_tags($name);  $name2 explode("|",$name1);  $namea=$name2[0];  $nameb=$name2[1];  ?>  <form name="user_info" id="user_info" method="post">   <input name="user_name" type="hidden" value="abc|def" /><br />   <input type="button" value="abc|def" onClick="saveUserInfo()">   </form>   </body>
value.php
PHP Code:
<?php  echo $_POST["user_name"];  ?>
youlichika is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to Problem in php ajax post value.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.14183 seconds with 12 queries