Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-22-2012, 02:20 PM   PM User | #1
mdviky87
New to the CF scene

 
Join Date: Feb 2012
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
mdviky87 is an unknown quantity at this point
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>
mdviky87 is offline   Reply With Quote
Old 02-22-2012, 04:00 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,384
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
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.
sunfighter is online now   Reply With Quote
Reply

Bookmarks

Tags
ajax, explode, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 02:51 PM.


Advertisement
Log in to turn off these ads.