473,804 Members | 2,265 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Evaluate string in javascript/AJAX

7 New Member
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 2456
acoder
16,027 Recognized Expert Moderator MVP
Remember to use code tags when posting code:
[CODE=javascrip t]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
johnhjohn
43 New Member
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
peace2007
7 New Member
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 Recognized Expert Moderator MVP
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
peace2007
7 New Member
Thank you very much acoder
Sep 22 '07 #6
acoder
16,027 Recognized Expert Moderator MVP
You're welcome.
Sep 23 '07 #7

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

Similar topics

2
2045
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
2279
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) web server, so this is not a cross-site scripting attack. But I would prefer not to taint the target page with any extra logic to do this. (I will if I must.) The calling page has these elements:
7
3779
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 of the active areas hidden from users. I have a page named test.htm that includes a file get.php in a <scripttag that will dynamically generate some javascript to write the imagemap. The get.php file will write a unique key to a session that will...
11
3835
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 between the pages, and in almost every case, I can set 'em up fine, provided the variables are in the link. The page the *holds* the booking information, though, is problematic. An example trip might include two European cities or towns with a...
0
9714
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10599
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10347
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10090
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9173
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7635
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3832
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.