[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

XML not being passed to Firefox, but in IE it works. Jquery Each,Find

Posted on 2009-04-10
3
Medium Priority
?
445 Views
Last Modified: 2013-12-07
Hi Guys

I think im formating my xml incorrectly


if you look in the data.php file at the top. i have added this line header('Content-type: text/xml');

that makes it work in IE. but then it doesnt work in Firefox, if i take it out, it doesnt work in IE but works in Firefox.. What am i doing wrong here?

<!--data.php file-->
 
<?php session_start();
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header('Content-type: text/xml');
include("./../include/php/inc.functions.php");
 
$Action = isset($_REQUEST['action']) ? $_REQUEST['action'] : die();
$UserId = intval(isset($_REQUEST['UserId']) ? $_REQUEST['UserId'] : "");
$MessageId = intval(isset($_REQUEST['MessageId']) ? $_REQUEST['MessageId'] : "");
$Text = fixString(isset($_REQUEST['Text']) ? $_REQUEST['Text'] : "");
 
$myServer = "194.255.125.36";
$myUser = "vipper";
$myPass = "g7k39##f63qd##";
$myDB = "GoVip"; 
$conn = mssql_connect($myServer, $myUser, $myPass)
  or die("Couldn't connect to MySQL Server"); 
$selected = mssql_select_db($myDB, $conn)
  or die("Couldn't open database"); 
 
if($Action == 'SendMessage'){
	$insert = "
		INSERT MessengerConversations (FromUserId,ToUserId,Text) values (".$_SESSION['UserId'].",$UserId,'$Text')
	";
	mssql_query($insert);
	mssql_close($conn);
	die();
}
 
if($Action == 'GetFriends'){
	$select = "
		SELECT 
			DISTINCT(f1.FriendId),
			Users.UserId,
			Users.UserName,
			Users.Status, 
			Users.Region,
			Users.Gender,
			CASE WHEN DATEDIFF(Mi,getdate(),Users.OnlineTime) > -12 THEN 'Online' ELSE 'Offline' END IsOnline,
			(SELECT 
				COUNT(*) 
			FROM 
				MessengerConversations 
			WHERE 
				MessengerConversations.FromUserId = Users.UserId
				AND (ReadBy1 IS NULL OR ReadBy1 <> ".$_SESSION['UserId'].") 
				AND (ReadBy2 IS NULL OR ReadBy2 <> ".$_SESSION['UserId'].")
			) NewMessage
		FROM 
			Friends f1 
		JOIN friends f2 ON f1.frienduserid=f2.userid
		JOIN friends f3 ON f2.frienduserid = f3.userid
		LEFT JOIN Users ON f1.FriendUserId=Users.UserId
		WHERE 
			f1.userid = ".$_SESSION['UserId']."
			and f3.userid = ".$_SESSION['UserId']."
		ORDER BY IsOnline DESC,Gender DESC,UserName ASC 
	";
	$rs = mssql_query($select);
	$numRows = mssql_num_rows($rs); 
	if($numRows>0){
		$i=0;
		$color = "";
		echo '<?xml version="1.0" encoding="UTF-8"?>';
		echo "<friends>";
		while($row = mssql_fetch_array($rs)){
			echo "		
				<friend id='".$row['UserId']."'>
					<username>".$row['UserName']."</username>
					<userid>".$row['UserId']."</userid>
					<status>".$row['IsOnline']."</status>
					<newmessage>".$row['NewMessage']."</newmessage>
				</friend>
			";
		}
		echo "</friends>";
	}
	mssql_close($conn);
	die();
	
}
if($Action == 'GetConversation'){
	$select = "
		SELECT
			t1.MessageId,
			convert(char,t1.CreatedDate,108) CreatedDate,
			t1.FromUserId,
			t2.UserName FromUserName,
			t1.ToUserId,
			t3.UserName ToUserName,
			t1.Text
		FROM
			MessengerConversations t1
		LEFT JOIN Users t2 ON t1.FromUserId=t2.UserId
		LEFT JOIN Users t3 ON t1.ToUserId=t3.UserId
		WHERE
			(t1.FromUserId=".$_SESSION['UserId']." OR t1.ToUserId=".$_SESSION['UserId'].")
			AND (t1.FromUserId=$UserId OR t1.ToUserId=$UserId)
			AND (ReadBy1 IS NULL OR ReadBy1 <> ".$_SESSION['UserId'].")
			AND (ReadBy2 IS NULL OR ReadBy2 <> ".$_SESSION['UserId'].")
		ORDER BY
			t1.CreatedDate ASC
		
		UPDATE 
			MessengerConversations 
		SET 
			ReadBy1 = isnull(ReadBy1,".$_SESSION['UserId']."),
			ReadBy2 = (case WHEN ReadBy1 IS NOT NULL AND ReadBy1<>".$_SESSION['UserId']." THEN ".$_SESSION['UserId']." ELSE ReadBy2 END)
		WHERE 
			(FromUserId = ".$_SESSION['UserId']." OR ToUserId = ".$_SESSION['UserId'].") 
			AND (FromUserId = ".$UserId." OR ToUserId = ".$UserId.")
		
	";
	$rs = mssql_query($select);
	$numRows = mssql_num_rows($rs); 
	if($numRows>0){
		$i=0;
		$color = "";
		echo '<?xml version="1.0" encoding="UTF-8"?>';
		echo "<conversations>";
		while($row = mssql_fetch_array($rs)){
			echo "		
				<conversation id='".$row['UserId']."' messageId='".$row['MessageId']."'>
					<createddate>".$row['CreatedDate']."</createddate>
					<fromuserid>".$row['FromUserId']."</fromuserid>
					<fromusername>".$row['FromUserName']."</fromusername>
					<touserid>".$row['ToUserId']."</touserid>
					<tousername>".$row['ToUserName']."</tousername>
					<theText>".$row['Text']."</theText>
				</conversation>
			";
		}
		echo "</conversations>";
	}else{
		echo "<conversations>";
		echo "</conversations>";
	}
	mssql_close($conn);
	die();
	
}
 
 
?>
 
 
 
 
<!-- JAVASCRIPT FUNCTION TO GET IT-->
 
function TCMessenger_GetFriends(){
	
	$.ajaxq ("TCMessenger_Queue", {
		url: "/TCMessenger/data.php?action=GetFriends",
		cache: false,
		success: function(html)
		{
		
			$(html).find('friend').each(function(){
				         
                var id = $(this).attr('id');
                var UserName = $(this).find('username').text();
                var UserId = $(this).find('userid').text();
                var Status = $(this).find('status').text();
                var NewMessage = $(this).find('newmessage').text();
                if(document.getElementById('TCMessenger_Friend_'+id)==null)
					$("<tr id='TCMessenger_Friend_"+id+"' onclick='TCMessenger_OpenConversation("+id+");' onmouseover='TCMessenger_ConversationHiLight(this.id,\"over\");' onmouseout='TCMessenger_ConversationHiLight(this.id,\"out\");' UserId='"+id+"' UserName='"+UserName+"' class='TCMessenger_Friend'><td>"+UserName+"</td><td id='TCMessenger_FriendStatus_"+id+"'>"+Status+"</td><td id='TCMessenger_NewMessage_"+id+"'></td></tr>").appendTo("#TCMessenger_FriendsListTable");
				
				if(document.getElementById('TCMessenger_Friend_'+id)!=null && document.getElementById('Conversation_'+UserId)==null && Status=='Offline')
					$("#TCMessenger_Friend_"+id).remove();
				var State = $("#TCMessenger_FriendStatus_"+id).text();
				if(Status!=State)
					$("#TCMessenger_FriendStatus_"+id).text(Status);
				if(!$("#TCMessenger_Friend_"+id).attr("active") && NewMessage>0){
					document.getElementById('TCMessenger_NewMessage_'+id).innerHTML = "<img src='/images/icons/talk.png'>";
				}
				
						
            });
          
		}
	});	
}

Open in new window

0
Comment
Question by:tim_carter
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Expert Comment

by:brandonvmoore
ID: 24114066
I don't know the answer to your question, but a possible solution until you find one is to check which browser is calling and send the appropriate response.
0
 
LVL 1

Accepted Solution

by:
tim_carter earned 0 total points
ID: 24114113
i have solved it like this

if(!(strpos($_SERVER['HTTP_USER_AGENT'],'Mozilla/5') === false)) {
      //
}elseif(!(strpos($_SERVER['HTTP_USER_AGENT'],'Opera') === false)) {
      //
}else {
      header('Content-type: text/xml');      
}

i know its not the right way to do it, but dont know how else to solve it actually.. without the header content-type it works in, FF/Chrome/Opera. but not IE. so im just detechting if it is IE, and inserting it
0
 
LVL 39

Expert Comment

by:abel
ID: 24114550
> i have added this line header('Content-type: text/xml');

this is a known and long-standing bug with IE not using and understanding the proper header of "application/xml". Here's one of the many posts on the subject: http://www.petefreitag.com/item/381.cfm
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question