无法使用$ .ajax调用WebMethod来传递JSON数据

时间:2014-03-07 06:13:32

标签: jquery json vb.net webmethod

我想调用我的VB页面中写的webmethod。为此我写了下面的代码。但是,它会直接进入 error 块并显示消息 undefined

的JavaScript

function fnSaveReview(){
   var content = new Object();
   content.TableName = "BAChildProjects"
   content.ColumnName = "cIsQCApproved"
   content.ColumnValue = "Y"
   content.Refcolumn = "vWorkSpaceId"
   content.RefValue = $('#<%= HProjectId.ClientId%>').val();
   var JsonString=JSON.stringify(content);

   $.ajax({
          type: "POST",
          url: "frmBAProjectDefinition.aspx/UpdateFieldValues",
          data: JsonString,          
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          success: function(data) {
               alert('Data Reviewed Successfully.');          
          },
          failure: function(error) {
               alert(error);
          },
          error: function (data) {
               debugger ;
               alert(data.d);
          }
     });
}

VB.NET

<Web.Services.WebMethod()> _
    Public Shared Function UpdateFieldValues(ByVal JSONString As String) As String

        Dim objhelpDb As New WS_HelpDbTable.WS_HelpDbTable
        Dim objLambda As New WS_Lambda.WS_Lambda
        Dim eStr As String = String.Empty
        Dim ds_Save As New DataSet
        Try

            ds_Save.Tables.Add(JsonConvert.DeserializeObject(JSONString, GetType(System.Data.DataTable)))


            If Not objLambda.Save_UpdateFieldValues(WS_Lambda.DataObjOpenSaveModeEnum.DataObjOpenMode_Add, ds_Save, _
                                                 HttpContext.Current.Session(S_UserID), eStr) Then
                Return False
                Exit Function
            End If

            Return True
        Catch ex As Exception
            Return False
        End Try

    End Function

CONSOLE.LOG(数据);

Object {readyState: 4, setRequestHeader: function, getAllResponseHeaders: function, getResponseHeader: function, overrideMimeType: function…}
abort: function (a){a=a||"abort",p&&p.abort(a),w(0,a);return this}
always: function (){return i.done.apply(i,arguments).fail.apply(i,arguments)}
complete: function (){if(c){var a=c.length;m(arguments),i?k=c.length:e&&e!==!0&&(j=a,n(e[0],e[1]))}return this}
done: function (){if(c){var a=c.length;m(arguments),i?k=c.length:e&&e!==!0&&(j=a,n(e[0],e[1]))}return this}
error: function (){if(c){var a=c.length;m(arguments),i?k=c.length:e&&e!==!0&&(j=a,n(e[0],e[1]))}return this}
fail: function (){if(c){var a=c.length;m(arguments),i?k=c.length:e&&e!==!0&&(j=a,n(e[0],e[1]))}return this}
getAllResponseHeaders: function (){return s===2?n:null}
getResponseHeader: function (a){var c;if(s===2){if(!o){o={};while(c=bJ.exec(n))o[c[1].toLowerCase()]=c[2]}c=o[a.toLowerCase()]}return c===b?null:c}
isRejected: function (){return!!e}
isResolved: function (){return!!e}
overrideMimeType: function (a){s||(d.mimeType=a);return this}
pipe: function (a,b,c){return f.Deferred(function(d){f.each({done:[a,"resolve"],fail:[b,"reject"],progress:[c,"notify"]},function(a,b){var c=b[0],e=b[1],g;f.isFunction(c)?i[a](function(){g=c.apply(this,arguments),g&&f.isFunction(g.promise)?g.promise().then(d.resolve,d.reject,d.notify):d[e+"With"](this===i?d:this,[g])}):i[a](d[e])})}).promise()}
progress: function (){if(c){var a=c.length;m(arguments),i?k=c.length:e&&e!==!0&&(j=a,n(e[0],e[1]))}return this}
promise: function (a){if(a==null)a=h;else for(var b in h)a[b]=h[b];return a}
readyState: 4
responseText: "<html>
↵    <head>
↵        <title>The resource cannot be found.</title>
↵        <style>
↵         body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} 
↵         p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
↵         b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
↵         H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
↵         H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
↵         pre {font-family:"Lucida Console";font-size: .9em}
↵         .marker {font-weight: bold; color: black;text-decoration: none;}
↵         .version {color: gray;}
↵         .error {margin-bottom: 10px;}
↵         .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
↵        </style>
↵    </head>
↵
↵    <body bgcolor="white">
↵
↵            <span><H1>Server Error in '/BizNET' Application.<hr width=100% size=1 color=silver></H1>
↵
↵            <h2> <i>The resource cannot be found.</i> </h2></span>
↵
↵            <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">
↵
↵            <b> Description: </b>HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. &nbsp;Please review the following URL and make sure that it is spelled correctly.
↵            <br><br>
↵
↵            <b> Requested URL: </b>/BizNET/frmBAProjectDefinition.aspx/UpdateFieldValues<br><br>
↵
↵            <hr width=100% size=1 color=silver>
↵
↵            <b>Version Information:</b>&nbsp;Microsoft .NET Framework Version:2.0.50727.5420; ASP.NET Version:2.0.50727.5459
↵
↵            </font>
↵
↵    </body>
↵</html>
↵<!-- 
↵[HttpException]: The file '/BizNET/frmBAProjectDefinition.aspx' does not exist.
↵   at System.Web.UI.Util.CheckVirtualFileExists(VirtualPath virtualPath)
↵   at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
↵   at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
↵   at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert)
↵   at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert)
↵   at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)
↵   at System.Web.UI.PageHandlerFactory.GetHandler(HttpContext context, String requestType, String virtualPath, String path)
↵   at System.Web.HttpApplication.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
↵   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
↵-->"
setRequestHeader: function (a,b){if(!s){var c=a.toLowerCase();a=m[c]=m[c]||a,l[a]=b}return this}
state: function (){return e}
status: 404
statusCode: function (a){if(a){var b;if(s<2)for(b in a)j[b]=[j[b],a[b]];else b=a[v.status],v.then(b,b)}return this}
statusText: "Not Found"
success: function (){if(c){var a=c.length;m(arguments),i?k=c.length:e&&e!==!0&&(j=a,n(e[0],e[1]))}return this}
then: function (a,b,c){i.done(a).fail(b).progress(c);return this}
__proto__: Object
undefined

我的主要问题是调试器甚至没有转到WebMethod的{​​{1}}

1 个答案:

答案 0 :(得分:0)

这是一个匿名问题,我在这个问题上花了很多时间。我可以通过以下方式解决此问题。

第一类

  1. 清除解决方案(Build - &gt; Clear Solution)
  2. 然后重建解决方案(Build - &gt; Rebuild Solution)
  3. II型

    1. 关闭整个解决方案(文件 - &gt;退出)
    2. 然后重新打开您的解决方案。
    3. 通过上述步骤,您可以解决该问题。