Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net Chrome中ajax请求期间的空响应,但不包括IE或FF_Asp.net_Ajax_Google Chrome_Response - Fatal编程技术网

Asp.net Chrome中ajax请求期间的空响应,但不包括IE或FF

Asp.net Chrome中ajax请求期间的空响应,但不包括IE或FF,asp.net,ajax,google-chrome,response,Asp.net,Ajax,Google Chrome,Response,在Chrome中使用asp.net而不是IE或FF调用web方法时,我收到一个空响应。我使用ASP PageMethod.func以及jquery ajax调用获得此行为 我可以通过在服务器上添加一个延迟睡眠调用来“修复”这个症状,这让我相信代码在某些地方是完全错误的。我有webkit修复程序,因此Chrome正在使用webkit(请参阅日志的第一行) 我创建了一个简单的测试用例。显示从左到右按下每个按钮的日志。基本上,在服务器上没有睡眠调用的情况下,加载失败的时间超过95%。睡眠(0)调用其5

在Chrome中使用asp.net而不是IE或FF调用web方法时,我收到一个空响应。我使用ASP PageMethod.func以及jquery ajax调用获得此行为

我可以通过在服务器上添加一个延迟睡眠调用来“修复”这个症状,这让我相信代码在某些地方是完全错误的。我有
webkit
修复程序,因此Chrome正在使用
webkit
(请参阅日志的第一行)

我创建了一个简单的测试用例。显示从左到右按下每个按钮的日志。基本上,在服务器上没有睡眠调用的情况下,加载失败的时间超过95%。睡眠(0)调用其50%,大睡眠1秒很少(如果有)失败

如果我取消睡眠,打开小提琴,它永远不会失败。有点像没有被冲红的反应

测试用例是否有明显的错误,或者这是一个bug

标题上的fiddler响应如下所示,有51个字节的数据(未显示):

日志:

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 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>
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;
        }    
    }
}

你有公共复制URL吗?当你说“有webkit补丁”时,你是什么意思?你使用的是什么版本的Chrome?我现在在一台家用机器上,但除了jquery-1.3.2库和webkit修复程序外,这个示例已经完成。webkit修复程序不会影响结果,因此可能甚至不需要它,但它就在这里(请参阅文章末尾):Chrome的版本是:2.0.172.33这很奇怪,因为如果我用一个更简单的HelloWorld()Web方法替换OnClick(s1,s2,I),该方法不带返回简单字符串的参数,那么一切都可以正常工作,而无需添加任何延迟,这让我想知道锁、线程、定时、网络刷新问题。克里斯
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;
        }    
    }
}