【问题标题】:Sys.ParameterCountException: Parameter count mismatchSys.ParameterCountException:参数计数不匹配
【发布时间】:2012-06-17 10:41:54
【问题描述】:

我在firefoxgoogle chrome 面临以下问题:

Sys.ParameterCountException: Parameter count mismatch. 

我调用下面的javascript方法onclick

<script type="text/javascript">
        var confirmSubmited = false;
        function SubmitWithLog(par_name, par_address, frm) {

            jQuery.ajax({
                url: "/LogAction.ashx?par_name=" + par_name + "&par_address=" + par_address,
                type: "GET",
                timeout: 3000,
                async: true, // you can try and async:false - maybe is better for you
                data: action = 4, // here you send the log informations
                cache: false,
                success: function(html) {
                    jQuery(frm).submit();
                },
                error: function(responseText, textStatus, XMLHttpRequest) {
                    jQuery(frm).submit();
                }
            });

            return false;
        }
    </script>

来自 firebug 的链接将呈现如下:

<a href="#" onclick="SubmitWithLog('%d8%b7%d9%84%d8%a8+%d8%a5%d9%84%d8%aa%d9%85%d8%a7%d8%b3+‌​%d9%84%d9%84%d9%85%d9%88%d8%a7%d8%b1%d8%af+%d8%a7%d9%84%d8%a8%d8%b4%d8%b1%d9%8a%d‌​8%a9','...../RequestList.aspx','#ctl43');return false;">GO </a>

根据以下链接:

Error: Sys.ParameterCountException: Parameter count mismatch.

我设置了ScriptMode = "release"

但我得到另一个错误

this._toFormattedString is not a function

IE不存在这个问题。


编辑:

public class LogAction : IHttpHandler, System.Web.SessionState.IRequiresSessionState
    {


        public void ProcessRequest(HttpContext con)
        {
            // log here what you wish
            string[] statistics = TrackUser();
            string a = HttpUtility.UrlDecode(con.Request.Params["Par_name"].ToString());
            string b = con.Request.Params["Par_address"].ToString();

            TraceActivity(a, b, statistics[0], statistics[1], statistics[2]);
            // end up with no content
            con.Response.TrySkipIisCustomErrors = true;
            con.Response.Status = "204 No Content";
            con.Response.StatusCode = 204;
        }

    //-------------------------------------------
    }

【问题讨论】:

  • 我不确定这段代码是否与错误有关,是否可以给我网页上的真实网址以查看完整页面?
  • 网站仍处于开发阶段:(
  • 错误来自您的 Ajax 请求还是来自您的表单提交? LogAction.ashx 有什么作用?能发下相关的服务器端代码吗?
  • @just_name 该错误看起来像一个 .NET 错误,因此来自 LogAction.ashx。 (ScriptMode = "release" 只对客户端隐藏错误;它不能解决任何问题。)链接在 IE 中呈现什么?
  • 请在加载 jQuery 后立即添加 $.noConflict();。正如你在这里看到的:api.jquery.com/jQuery.noConflict

标签: javascript jquery asp.net ajax updatepanel


【解决方案1】:

当您使用错误数量的参数调用 ajax API 的公共方法时会发生这种情况。例如,尝试Boolean.parse("true", "what?")。它只需要 1 个参数,你传入 2 或者你发送一个空值。

您的提交链接...../RequestList.aspx 看起来也不是正确的地址。 所以请确保您没有传递 null 或错误的参数。

【讨论】:

  • @just_name 有 cmets 吗?这应该是您收到此错误的唯一原因。如果答案没有导致解决方案,请显示您的 ashx 函数...
  • ajax APi 的公共方法是什么意思,我不认为我使用这样的东西。我将展示 ashx 函数
  • @just_name 在您的函数中将 Par_name Par_address 更改为小写。
  • 同样的错误:this._toFormattedString is not a function http://localhost:6450/Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&amp;compress=1&amp;_TSM_CombinedScripts_=%3b%3bSystem.Web.Extensions%2c+Version%3d3.5.0.0%2c+Culture%3dneutral%2c+PublicKeyToken%3d31bf3856ad364e35%3aen-US%3a7263e9c6-5962-41bc-b839-88b704bfcf0d%3aea597d4b%3ab25378d2%3bTelerik.Web.UI%2c+Version%3d2011.2.712.35%2c+Culture%3dneutral%2c+PublicKeyToken%3d121fae78165ba3d4%3aen-US%3a326e32e2-cd52-462c-ba2c-db5128e4371b%3a16e4e7cd%3addbfcb67%3af7645509%3a24ee1bba%3a19620875%3a3f6e8f3f Line 6
【解决方案2】:

可能值得包装您的数据:引号中的项目

data: action = 4

变成

data: "action = 4"

【讨论】:

    【解决方案3】:

    在 de web.config 中设置 debug="false" 似乎可以消除错误

    【讨论】:

    • 这行得通。您需要从 web.config 中的“configuration/system.web/compilation”节点中删除 debug="true" 属性。或者设置为false。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-10
    • 1970-01-01
    • 2017-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-14
    相关资源
    最近更新 更多