Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Ajax
|
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
 
Old September 19th, 2007, 02:09 PM
Authorized User
 
Join Date: Sep 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default Evaluate responseText from Server.aspx

Hi,

I need to evaluate the return result of a function from Server.aspx as following. But it doesn't work as I need
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 GetBanType()
{    
   rnd++;

    url = 'Server.aspx?action=GetBan&session=' + rnd ;
    var re = getAjax();

    re.onreadystatechange = function(){    
        if( re.readyState == 4 && re.status == 200 ) 
        {        
            if(re.responseText != "")
            {            
                if (re.responseText == "special value")
                {
                            ....
Actually, I call Server.aspx from many other functions as well and I set javascript control text to the return result of Server.aspx without any problem; but I cannot recognize the problem with above code.

Any idea is appreciated.

 
Old September 19th, 2007, 02:35 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Well it would help if you showed what responseText contained and how this differs from what you expect.

--

Joe (Microsoft MVP - XML)
 
Old September 20th, 2007, 02:43 PM
Authorized User
 
Join Date: Sep 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default


the re.responseText contains:
"

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

"
while I expect a single word like "word" from it.

 
Old September 20th, 2007, 03:03 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Seems like a problem with your web service then. Have you tried debugging with Fiddler to see the raw request and response?

--

Joe (Microsoft MVP - XML)
 
Old September 20th, 2007, 11:27 PM
Authorized User
 
Join Date: Sep 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks John for the reply!
Since I'm new to fiddler I'm not getting what's going on there.
 
Old September 21st, 2007, 02:56 AM
Authorized User
 
Join Date: Sep 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

finally I found the problem but not the solution.
Actually, re.responseText returns:
"Gag

&nbsp;
<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?

Thanks & Regards

 
Old September 21st, 2007, 08:38 AM
jminatel's Avatar
Wrox Staff
Points: 18,059, Level: 58
Points: 18,059, Level: 58 Points: 18,059, Level: 58 Points: 18,059, Level: 58
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2003
Posts: 1,906
Thanks: 62
Thanked 139 Times in 101 Posts
Default

Peace2007: If you're still looking to learn a bit more about Fiddler, this article by Nicholas Zakas, from our Professional Ajax book (http://www.wrox.com/WileyCDA/WroxTit...470109491.html - which Joe co-authored) might be of help:
http://www.wrox.com/WileyCDA/Section/id-303210.html


Jim Minatel
Acquisitions Director
Wiley Technology Publishing
WROX Press

Last edited by jminatel; May 18th, 2016 at 04:08 PM.. Reason: deleted dead link
 
Old September 21st, 2007, 08:47 AM
Authorized User
 
Join Date: Sep 2007
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you Jim :)



 
Old January 4th, 2008, 06:47 AM
Authorized User
 
Join Date: Jul 2007
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to mujahidkhaleel
Default

I guess the Server.aspx page has many break tags, remove those tags from the Server.aspx or after Response.Write("Gag") call Response.End()

Hope it helps.

Mujahid Khaleel
Web designing, development, E-commerce applications.





Similar Threads
Thread Thread Starter Forum Replies Last Post
ResponseText property of XMLHTTPRequest Object prashantshekhar BOOK: Beginning Ajax with ASP.NET 1 August 28th, 2009 07:28 AM
How to evaluate parameter? chobo XSLT 8 February 25th, 2008 07:05 AM
Unknow runtime error with req.responseText peace2007 Ajax 14 September 21st, 2007 08:44 AM
responseText not working in FireFox Coyote21 BOOK: Professional Ajax ISBN: 978-0-471-77778-6 0 July 13th, 2006 05:53 AM
How do i evaluate A_josh VB How-To 1 December 22nd, 2003 01:47 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.