Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation split response text in ajax

    I want to split response text in ajax and display in two places in php using document.getElementById



    this is my js

    Code:
    function approve(e) {
    	var req = getXMLHTTP();
    	if (req) {
    			
    			req.onreadystatechange = function() {
    				if (req.readyState == 4) {
    					// only if "OK"
    					if (req.status == 200) {
    						var resp = req.responseText;
    						
    						document.getElementById("get"+e).innerHTML=req.responseText;
    						<!--document.getElementById("status").innerHTML=;-->
    					} else {
    						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
    					}
    				}				
    			}			
    			req.open("GET", "approve.php?stu="+e, true);
    			req.send(null);
    		}
    	}
    Code:
    <html>
    <head><link rel="stylesheet" type="text/css" href="sts_style.css"  /></head>
    <body>
    <?php
    	require_once 'connect.php';
    	$id = $_REQUEST['stu'];
    	$upd = mysql_query ("UPDATE stud SET approve = '1' WHERE s_id = ".$id." ");
    	if ($upd) {
    		//<div class="c_seven" id="get"><p class="text"></p></div>			
    		echo "Approved ";
    	}
    	else
    		die("Error");
    	
    	//status
    	$status = mysql_query("SELECT * FROM stud WHERE s_id = '".$id."' ");
    	$qry = mysql_fetch_array($status);
    	
    	if($qry['approve'] == '1') {
    			?>
    			<div class="app"> <?php
    			echo "<b>".$qry['name'] ."</b>"." Approved Successfully "." <br />";
    			?>
    			</div>
    			<?php
    		}
    ?>
    </body>
    </html>

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,692
    Thanks
    25
    Thanked 657 Times in 656 Posts
    This is the line that needs to be changed
    Code:
    document.getElementById("get"+e).innerHTML=req.responseText;
    Put a delineater mark in the returning text like ~ between the two messages.
    Set a variable equal to the req.responseText; and then split the string at the ~
    Use innerHTML to post both sections of the string to where you want.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •