 |
| Ajax the combination of XHTML, CSS, DOM, XML, XSLT, XMLHttpRequest, and JavaScript |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Ajax section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

September 14th, 2007, 01:42 AM
|
|
Authorized User
|
|
Join Date: Sep 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Unknow runtime error with req.responseText
Hi,
I'm developing a chat application using Asp.Net and AJAX; I have these functions in my js file:
Code:
function getAjax()
{
var XmlHttp;
//Creating object of XMLHTTP in IE
try
{
XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(oc)
{
XmlHttp = null;
}
}
//Creating object of XMLHTTP in Mozilla and Safari
if(!XmlHttp && typeof XMLHttpRequest != "undefined")
{
XmlHttp = new XMLHttpRequest();
}
return XmlHttp;
}
function getUserList()
{
rnd++;
url = 'Server.aspx?action=UserList&session=' + rnd;
req = getAjax();
req.onreadystatechange = function(){
if( req.readyState == 4 && req.status == 200 )
{
obj = getElement( "userlist" );
obj.innerHTML = req.responseText;
getBufferText();
}
}
req.open( 'GET', url, true );
req.send( null );
}
When the first user logs in, the getUserList() is executed and returns user list without any problem. But when the second user logs in, obj.innerHTML = req.responseText; throws "Unknown Runtime exception" error.
Any idea is appreciated:)
|
|

September 14th, 2007, 04:49 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Might well be a problem with the web service. You could try accessing the URL directly in the browser from more than one window to see if it works as expected.
--
Joe ( Microsoft MVP - XML)
|
|

September 14th, 2007, 09:49 AM
|
|
Authorized User
|
|
Join Date: Sep 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for the reply Joe!
It should be a problem with my server side code, but I wasn't able to find out yet :(
Maybe a silly question but I'm new in this field:
I'm having Global.asax.cs file in my application, in which I set some variables from code behind pages and use those variables in my server side code; like: Logged on user ID, etc. is it correct? or these variables differs for each user in server side?
|
|

September 14th, 2007, 12:24 PM
|
|
Authorized User
|
|
Join Date: Sep 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Well.. I found out the problem but don't know the solution (one step ahead ):D
When user logs in I create a session as:
Code:
Guid g = Guid.NewGuid();
//Save Session Data
Session["userid"] = g.ToString();
and when I try to return the user list I read the user id trough the session:
Code:
string userid = (string)Session["userid"];
but for the second user these two values differ!
Any Suggestion?
|
|

September 15th, 2007, 09:06 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Sessions are normally managed via cookies which the browser handles, when you use XMLHttp you have to take some of the strain yourself. I think you'll need to find a different way to manage sessions. One way is to create the GUID as you do but to pass it back to the client as part of the response. Next time you need the data you send the GUID in the query string. You'll need to store the actual user list and session IDs in a global store such as the Cache.
--
Joe ( Microsoft MVP - XML)
|
|

September 15th, 2007, 09:23 AM
|
|
Authorized User
|
|
Join Date: Sep 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you Joe for the complete and helpful comments
I did as your explanation and my problem gone away
|
|

September 15th, 2007, 09:26 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Hell's bells, you're a quicker coder than I am...
--
Joe ( Microsoft MVP - XML)
|
|

September 15th, 2007, 01:05 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Quote:
quote:Originally posted by joefawcett
Sessions are normally managed via cookies which the browser handles, when you use XMLHttp you have to take some of the strain yourself. I think you'll need to find a different way to manage sessions.
|
Joe,
Isn't an XMLHttp request just like a standard Http request from the browser? That is, it sends all the same Http headers (including cookies) as you get with a standard GET or POST. I have done plenty of ajax with several different http request classes (ASP.NET Ajax framework and a java class) and never had to handle sessions any differently than with standard ASP.NET pages.
-Peter
|
|

September 15th, 2007, 10:34 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
In theory yes but without having detailed knowledge of the poster's code it was the best suggestion I could think of.
--
Joe ( Microsoft MVP - XML)
|
|

September 16th, 2007, 12:44 AM
|
|
Authorized User
|
|
Join Date: Sep 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Actually, my application was running without any problem till I made a few changes to my server.aspx, which caused the pre-mentioned problem.
Unfortunately, I'm in too hurry to dedicate time for that now. But I'll be providing more detail soon to get the rational solution from you.
Thanks again!
|
|
 |