2011-11-18 45 views
0
%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %> 

<!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 runat="server"> 
    <title></title> 
</head> 
<body> 
    <script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script> 
    <script type="text/javascript"> 
     $(document).ready(function() { 
      debugger; 
      var counter = "test"; 
      WebApplication1.Service1.DoWork(counter, ResultLoadMainGridProductType, ErrorLoadMainGridProductType); 
     }); 
     function ResultLoadMainGridProductType() { 


     } 
     function ErrorLoadMainGridProductType() { 


     } 
    </script> 
    <form id="form1" runat="server">  
    <div> 
    <asp:ScriptManager ID="ScriptManager" runat="server">    
      <Services> 
       <asp:ServiceReference Path="~/Service1.svc" /> 
      </Services> 
     </asp:ScriptManager> 
    </div> 
    </form> 
</body> 
</html> 

代碼失敗WebApplication1.Service1.DoWork(counter, ResultLoadMainGridProductType, ErrorLoadMainGridProductType); 錯誤:Microsoft Jscript的實現錯誤:「WebApplication1」不確定。 WebApplication1 - 命名空間...然後我看它在JavaScript代碼工作未定義。 如何讓它在那裏?如何在asp.net web上獲取JavaScript上的命名空間?

+0

WebApplication1.Service1.DoWork是一種服務器端方法嗎? –

回答

0

嘗試

$(document).ready(function() { 
    debugger; 
    var counter = "test"; 
    var service1 = new WebApplication1.Service1(); 
    service1.DoWork(counter, ResultLoadMainGridProductType, ErrorLoadMainGridProductType); 
}); 

同時檢查以確保在JavaScript文件jsdebug是在你的加載腳本。

+0

線上出現同樣的錯誤:var service1 = new WebApplication1.Service1() –

+0

是否存在jsdebug?當您直接導航到WCF服務時會發生什麼?例如http:// localhost:(portnumber)/Service1.svc? –

+0

但jsdebug實際上沒有加載:) web.config錯誤)) –