Solved

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

Posted on 2009-04-10
3
425 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
3 Comments
 
LVL 5

Expert Comment

by:brandonvmoore
Comment Utility
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
Comment Utility
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
Comment Utility
> 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

#Citrix #Internet Explorer #Enterprise Mode #IE 11 #IE 8
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now