2013-12-18 50 views
0

我正在尝试使用jQuery调用驻留在.aspx页面上的WebMethod。在开发环境(localhost)中工作正常,但是当我从服务器运行它时,似乎WebMethod根本没有被调用。我使用的服务器环境工具是.Net 2.0 SP2,IIS7.5和Visual Studio 2005.尝试使用jQuery调用驻留在.aspx页面上的WebMethod

正在调用的WebMethod将创建并写入.xml文件。然后通过另一种找不到它的方法来搜索此文件,因为WebMethod未执行且该文件从未创建。

这些都是我为了试图解决这个问题的东西:

•添加一个ScriptManager。我将其从.aspx文件中删除,因为它没有解决问题,并且在博客中读取了为使WebMethod调用不起作用而不需要ScriptManager。

•在RadScriptManager中设置属性EnablePageMethods = true。目前它没有被设置为真,因为它没有解决问题。

•在web.config文件中添加一个ScriptModule。

•在web.config中添加的协议:

​​

我删除这些从Web.config文件,因为他们没有解决问题,并在博客中说,需要这些标签在阅读使用.net 1.1和IIS 5.0,IIS 5.1,IIS6.0运行的环境。

•为用户和池分配写入权限,以便他们能够写入文件夹。 (IIS 7.5)

我缺少Web.config文件中的东西吗?什么可能导致这个问题?

这里是将WebMethod:

[WebMethod] 
public static string GetContinuityofCareDocument(string continuityofCareDocument, string indicator, string endOffile) 
{ 
    string _filePrefix = indicator; 
    string _fileNamexml = @"C:\TempFile" + _filePrefix + ".xml"; 
    StreamWriter _txtFile = new StreamWriter(_fileNamexml, true); 
    _txtFile.Write(continuityofCareDocument); 
    _txtFile.Close(); 

     return " Success"; 
} 

这里是其中的WebMethod正从称为:

<script language="javascript" type="text/javascript"> 


function SendCcdtoServer(params,indicator,endOffile) { 
    jQuery.ajaxSetup({ async: true }); 
    jQuery.ajax({ 
    type: "POST", 
     url: '<%=ResolveUrl("WebServiceDisplayCCD.aspx")%>'+'/GetContinuityofCareDocument', 
     data: '{continuityofCareDocument: "'+params+'", indicator: "'+indicator+'", endOffile:    "'+endOffile+'"}', 
     contentType: "application/json; charset=utf-8", 
     dataType: "json", 
     success: OnSuccess, 
     error: function(response) { 
      alert("response + failure "); 
     } 
    }); 
} 
function OnSuccess(response) { 
    alert("Success"); 
} 


</script> 

下面是在Web.config:

<configuration> 
    <configSections> 
     <sectionGroup name="Localization"> 
      <section name="Localization"      type="Localization.LocalizationConfigurationHandler, Localization,Version=1.0.0.0, Culture=neutral, PublicKeyToken=CA5930580A5E0032" /> 
     </sectionGroup> 
    </configSections> 


    <system.web> 

     <pages enableViewStateMac="false" validateRequest="true"       enableEventValidation="false" viewStateEncryptionMode="Never"      smartNavigation="false" /> 
     <httpModules> 
      <remove name="ScriptModule" /> 
      <add name="ScriptModule" type="System.Web.Handlers.ScriptModule,      System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,     PublicKeyToken=31bf3856ad364e35" /> 
     </httpModules> 
     <httpHandlers> 
      <add path="Telerik.Web.UI.WebResource.axd"         type="Telerik.Web.UI.WebResource" verb="*" validate="false" /> 
     </httpHandlers> 
     <compilation debug="true"> 
      <assemblies> 
       … 
      </assemblies> 
     </compilation> 
     <sessionState mode="SQLServer" sqlConnectionString="Data       Source=###.###.###.#;User ID=XXXXX;password=XXXXXX"        cookieless="false" timeout="60" /> 
     <globalization enableClientBasedCulture="true" /> 

    </system.web> 


    <location allowOverride="true" inheritInChildApplications="true"> 
     <appSettings> 
      <add key="Authentication" value="Windows" /> 
     </appSettings> 
    </location> 

    <system.webServer> 
     <validation validateIntegratedModeConfiguration="false" /> 
     <handlers> 
      <add name="Telerik_Web_UI_WebResource_axd" verb="*"         preCondition="integratedMode" path="Telerik.Web.UI.WebResource.axd"     type="Telerik.Web.UI.WebResource"/> 
     </handlers> 
    </system.webServer> 

</configuration> 

当使用chrome的开发人员工具我得到一个500错误,其中指出“无效的JSON”并包含t他整个页面的脚本。

在搜索此错误的可能解决方案后,我得到许多关于如何解决“无效的JSON基元”错误的博客,这似乎并不适用于我正在处理的问题。

这可能是什么原因造成的?

+0

'failure'不是一个有效的jQuery的AJAX的设置。你应该设置它'错误'。 –

+0

@Brad,我做了你所建议的改变,现在我在ajax调用失败时收到错误消息。它看起来像我仍然遇到同样的问题,WebMethod根本没有执行,因为.xml文件没有被写入文件夹。谢谢。 –

+0

如果它生产但没有生存,那会导致我怀疑它是不是ResolveUrl或其他产品。 ResolveUrl和类似的东西往往在生产和生活之间挑剔。例如:http://www.codeproject.com/Articles/53460/ResolveUrl-in-ASP-NET-The-Perfect-Solution – JackArbiter

回答

0

尝试设置决心VAR和看看它在调试:

var url = '<%=ResolveUrl("WebServiceDisplayCCD.aspx")%>' 
+0

var url返回目录/subdirectoryname/WebServiceDisplayCCD.aspx。我为C:\ inetpub \ vhosts \ servername \ subdirectoryname \ WebServiceDisplayCCD.aspx \ GetContinuityofCareDocument这样的绝对路径更改了'<%= ResolveUrl(“WebServiceDisplayCCD.aspx”)%>',并且ajax调用仍然失败。谢谢。 –

+0

我缺少Web.config文件中的内容吗?还有什么可能导致这个问题? –

相关问题