473,378 Members | 1,037 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Evaluate string in javascript/AJAX

Hi,

I need to evaluate the return result of a function from Server.aspx as following. But it doesn't work as I need

Expand|Select|Wrap|Line Numbers
  1. function getAjax()
  2. {
  3.     var XmlHttp;    
  4.     //Creating object of XMLHTTP in IE
  5.     try
  6.     {
  7.         XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  8.     }
  9.     catch(e)
  10.     {
  11.         try
  12.         {
  13.             XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  14.         } 
  15.         catch(oc)
  16.         {
  17.             XmlHttp = null;
  18.         }
  19.     }
  20.     //Creating object of XMLHTTP in Mozilla and Safari 
  21.     if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
  22.     {
  23.         XmlHttp = new XMLHttpRequest();
  24.     }    
  25.     return XmlHttp;
  26. }
  27. function GetBanType()
  28. {    
  29.    rnd++;
  30.  
  31.     url = 'Server.aspx?action=GetBan&session=' + rnd ;
  32.     var re = getAjax();
  33.  
  34.     re.onreadystatechange = function(){    
  35.         if( re.readyState == 4 && re.status == 200 ) 
  36.         {        
  37.             if(re.responseText != "")
  38.             {            
  39.                 if (re.responseText == "special value")
  40.                 {
  41.                             ....
  42.  
Actually, re.responseText returns:
"Gag

 
<br />
<br />
<br />
<br />
<br />
<br />

"
while I'm expecting only "Gag" word.
Could I know how I can subtract only the first word of the return result? Or, is there any general solution to get a proper result from server .aspx

Any idea is appreciated.
Sep 21 '07 #1
6 2431
acoder
16,027 Expert Mod 8TB
Remember to use code tags when posting code:
[CODE=javascript]JS code here...[/code]

Your server-side script is displaying extra spaces and newlines. Get rid of them.

You could replace all spaces and newlines in the response too.
Sep 21 '07 #2
If the response from the server is incorrect, then the server must be coded incorrectly in some way. I could not find anything wrong with the javascript code, so check your server.aspx's code to make sure there are not any mistakes that could have caused this error.

Hope I helped!
Sep 22 '07 #3
Thanks John and acoder for replying!

I call following function in server.aspx:
Expand|Select|Wrap|Line Numbers
  1. private void processGetBan()
  2.         {
  3.             lock (syncRoot)
  4.             {
  5.                 string user = (string)Session["username"];
  6.                 string channelname = (string)Session["channel"];
  7.                 Response.Write(Global.Engine.GetChannel(channelname).GetBanType(user));
  8.             }
  9.         }
in which GetBanType() returns only "Gag" without any space, etc.
Is there anything wrong with my server code?
acoder, you've written that I can replace all spaces and newlines in the response too; could you please tell me how, through a sample? I'm new in javascript/ajax code
Sep 22 '07 #4
acoder
16,027 Expert Mod 8TB
Run the server-side code without Ajax and check the source code.

To remove spaces/newlines, use the string replace method.
Sep 22 '07 #5
Thank you very much acoder
Sep 22 '07 #6
acoder
16,027 Expert Mod 8TB
You're welcome.
Sep 23 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Markus Schuster | last post by:
Hi, I have the following javascript function: <script type="text/javascript"> function HTMLEncode( text ) { text = text.replace(/&/g, "&amp;") ; text = text.replace(/"/g, "&quot;") ;
15
by: Phlip | last post by:
Javascripters: I have an outer page and an inner iframe. The outer page calculates some javascript, and wants the inner frame to run it. The inner frame should hit a page on the same (private)...
7
by: trey.bason | last post by:
I know everyone who uses javascript at some point tries to think of a way to hide it from curious users/hackers, so here goes my question. I am trying to display an image map and keep the coords...
11
by: julie.siebel | last post by:
I'm working on a rather complex booking system for building European trips, in a combination of SQL/VBScript/Javascript. There are tons of query string variables that get passed back and forth...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.