2013-10-19 67 views
0

在我的asp.net mvc4的項目,我有下面的標記和jQuery Index.cshtml -jQuery的AJAX調用Web服務中MVC 4

<html> 
<head> 
<script src="~/js/jquery-2.0.3.min.js"></script> 

<script type="text/javascript"> 
    $(function() { 
     $('#btnLogin').click(function (e) { 

      e.preventDefault(); 
      $.ajax({ 
       type: "POST", 
       url: '@Url.Content("../../WebService1.asmx/HelloWorld")', 
     data: "{}", 
     contentType: "application/json; charset=utf-8", 
     dataType: "json", 
     async: true, 
     success: function() { 
      alert('success'); 
     }, 
     error: function() { 
      alert('error'); 
     } 
     }); 

     }); 
    }); 

</script> 
</head> 
<body> 
    <form> 
    <button "btnLogin">Sign in</button> 
    </form> 

但AJAX調用返回錯誤。任何幫助?

+0

在你的錯誤回調,做'的console.log(參數);',並找出是什麼錯誤。 –

+0

@Jason P,「undefined」 –

+0

嗯...那..不應該..無論如何,你也可以檢查xhr請求的瀏覽器工具的網絡標籤。迴應應該給你一些信息。 –

回答

0

,因爲Web服務的它可以調用它是這條線RouteConfig.cs或Global.asax中忽略的衝突 - MVC4路由規則

那麼簡單的插件之間的衝突。

routes.IgnoreRoute("{*x}", new { x = @".*\.asmx(/.*)?" }); 

我希望這可能是有用的