I have problem with the responseText property in Safari, Google Chrome and IE. Line 68 - the responseText is empty. This works fine in Firefox and Opera. Also i have this problem with the responseText only in the block that starts at line 61. I don't have problem with the responseText in other places in the source code. Please try to understand the last three sentences,i'm saying that because there are many people that reads only the first sentence and gives some absolutelly useless answer. Ok,i'll say it again anyway - this works fine in Firefox and Opera - the responseText has some value so everything is fine, but it doesn't have value(it's empty) in Safari, Chrome and IE. I don't see problem with my code,what's wrong?

Here is the code.

Recommended Answers

All 2 Replies

That code is a big mess; just to confirm whether this is a problem with your code or responseText on IE strip all the fluff and create a bare minimum snippet which just sends a single parameter and receives some random response in responseText. If it still doesn't work, post the minimized code [without your application logic] along with which version of IE/Chrome you are having problems with.

Hi!

Looks like I'm running into similar problem the previous poster had run into..

I am receiving an empty response when calling a web method using asp.net in Chrome but not IE nor FF. I get this behavior using the ASP PageMethod.func as well as using jquery ajax call.

I can 'fix' the symptom by adding a delay sleep call on the server which makes me believe code is just plain wrong somewhere. I have the webkit fix so that Chrome is using webkit (see first line of log).

I have created a near minimal test case. The log of pressing each button from left to right is shown. Basically with out a sleep call on the server the load fails > 95% of the time. With a sleep(0) call its 50% and with a large sleep 1 sec it rarely (if ever?) fails.

If I remove the sleep and turn on Fiddler it never fails. Something like the response not getting flushed??

Is there something obviously wrong with the test case or is this a bug.

Thanks!!
Chris

Log:

0: Sys.Browser: [object Object], 530.5, WebKit
1: btnA -1
2: waiting for response now
3: btnJQA -1
4: waiting for response now
5: Result = EMPTY, textStatus =success
6: btnA 0
7: waiting for response now
8: Result = OnClick(.NET, page method, 0):  82 7/10/2009 1:01:01 PM
9: btnJQA 0
10: waiting for response now
11: Result = EMPTY, textStatus =success
12: btnA 1000
13: waiting for response now
14: Result = OnClick(.NET, page method, 1000):  84 7/10/2009 1:01:07 PM
15: btnJQA 1000
16: waiting for response now
17: Result = {"d":"OnClick(jquery, ajax, 1000):  85 7/10/2009 1:01:12 PM"}

Page Code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AjaxTest.aspx.cs" Inherits="PA.AjaxTest" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title></title>
    <script type="text/javascript" src="js/jquery-1.3.2.js"></script> 
    <script type="text/javascript">

        var iCount = 0;
        function log(s) {                           
            var l = $('#taLog');
            l.get()[0].value += iCount++ + ': ' + s + '\n';
            l.attr({ scrollTop: l.attr("scrollHeight") });
        }

        function btnA_Click(iMilliSec) {
            log("btnA " + iMilliSec);
            PageMethods.OnClick(".NET", "page method", iMilliSec,
            function(result, userContext, methodName) {
                log('Result = ' + ((result != null) ? result : 'result was null'));
            },
            function(error, userContext, methodName) {
                log('PM Response Error: ' + (error != null ? error.get_message() : "no_msg") + '\n\t' + userContext + '\n\t' + methodName);
            });

            log("waiting for response now");
        }

        function json_parse(data) {
            return (typeof (JSON) !== 'undefined' && typeof (JSON.parse) === 'function') ? JSON.parse(data) : eval('(' + data + ')');
        }

        function btnJQA_Click(iMilliSec) {
            log("btnJQA " + iMilliSec);
            $.ajax({
                type: "POST",
                url: "AjaxTest.aspx/OnClick",
                data: "{'s1': 'jquery', 's2': 'ajax', 'iMilliSec': '" + iMilliSec + "'}",
                timeout: 3000,
                cache: false,
                async: true,//false,
                //Connection: 'close',
                contentType: "application/json; charset=utf-8",
                //dataType: "json",  bypass eval of response for now
                dataFilter: function(data) {
                    return data;                    
                },
                success: function(msg, textStatus) {
                    log('Result = ' + (msg == '' ? 'EMPTY, textStatus =' + textStatus : msg));
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    log('Got an error = ' + (textStatus != null) ? textStatus : "no textstatus");
                }
            });
            log("waiting for response now");
        }

        function btnLoopA_Click() {}
        function btnLoopJQA_Click() { }
        
   </script>    

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
            <Scripts>
                <asp:ScriptReference Path="~/js/webkit.js" />
            </Scripts>
        </asp:ScriptManager>                  
       
        <input id="btnA" type="button" value="btnA" onclick='btnA_Click(-1)'/>       
        <input id="btnJQA" type="button" value="btnJQA" onclick='btnJQA_Click(-1)'/>           
        <input id="btnA_S0" type="button" value="btnA_0_sec" onclick='btnA_Click(0)'/>       
        <input id="btnJQA_S0" type="button" value="btnJQA_0_sec" onclick='btnJQA_Click(0)'/>           
        <input id="btnA_S1" type="button" value="btnA_1_sec" onclick='btnA_Click(1000)'/>       
        <input id="btnJQA_S1" type="button" value="btnJQA_1_sec" onclick='btnJQA_Click(1000)'/>                   
        <input id="btnLoopA" type="button" value="btnLoopA" onclick='btnLoopA_Click()'/>   
        <input id="btnLoopJQA" type="button" value="btnLoopJQA" onclick='btnLoopJQA_Click()'/>   
        
        <textarea id="taLog" cols="120" rows="15" style='position: fixed; left: 10px; bottom: 10px; right: 10px'></textarea>    
        
        <script type="text/javascript">
            log('Sys.Browser: ' + Sys.Browser.agent + ", " + Sys.Browser.version + ", " + Sys.Browser.name);
        </script>            
     </div>
    </form>
</body>
</html>

Server Code

using System;
using System.Web;
using System.Web.UI;
using System.ServiceModel.Web;
using System.Web.Services;

namespace PA
{
    public partial class AjaxTest : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e) {}
        static int __iCounter = 0;
        [WebMethod]        
        public static string OnClick(string s1, string s2, int iMilliSec)
        {
            if (iMilliSec >= 0)
                System.Threading.Thread.Sleep(iMilliSec);

            string sRet = "OnClick(" + s1 + ", " + s2 + ", " + iMilliSec + "):  " + __iCounter + " " + DateTime.Now.ToString();
            __iCounter++;
            
            return sRet;
        }    
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.