2

我正在尝试使用 Jquery AJAX调用 Web 服务http://www.w3schools.com/webservices/tempconvert.asmx 。

 function AppendListItems() {
            var webMethod = "http://www.w3schools.com/webservices/tempconvert.asmx/CelsiusToFahrenheit";
            jQuery.support.cors = true;
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                url: webMethod,
                data: { Celsius: "10" },
                success: function (msg) {

                    $("#lstPhoneNames").append("<li>" + msg.d + "</li>");
                },
                error: function (ex, a, b) {
                    alert(b);
                }
            });

        };

但是,调用失败它返回错误日志:

 <span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>

            <h2> <i>Runtime Error</i> </h2></span>

            <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">

            <b> Description: </b>An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
            <br><br>

            <b>Details:</b> To enable the details of this specific error message to be viewable on remote machines, please create a &lt;customErrors&gt; tag within a &quot;web.config&quot; configuration file located in the root directory of the current web application. This &lt;customErrors&gt; tag should then have its &quot;mode&quot; attribute set to &quot;Off&quot;.<br><br>

            <table width=100% bgcolor="#ffffcc">
               <tr>
                  <td>
                      <code><pre>

&lt;!-- Web.Config Configuration File --&gt;

&lt;configuration&gt;
    &lt;system.web&gt;
        &lt;customErrors mode=&quot;Off&quot;/&gt;
    &lt;/system.web&gt;
&lt;/configuration&gt;</pre></code>

                  </td>
               </tr>
            </table>

            <br>

            <b>Notes:</b> The current error page you are seeing can be replaced by a custom error page by modifying the &quot;defaultRedirect&quot; attribute of the application&#39;s &lt;customErrors&gt; configuration tag to point to a custom error page URL.<br><br>

            <table width=100% bgcolor="#ffffcc">
               <tr>
                  <td>
                      <code><pre>

&lt;!-- Web.Config Configuration File --&gt;

&lt;configuration&gt;
    &lt;system.web&gt;
        &lt;customErrors mode=&quot;RemoteOnly&quot; defaultRedirect=&quot;mycustompage.htm&quot;/&gt;
    &lt;/system.web&gt;
&lt;/configuration&gt;</pre></code>

                  </td>
               </tr>
            </table>

            <br>

    </body>

我是否以错误的方式调用服务?

4

3 回答 3

0

使用Fiddler等工具检查实际请求发送到服务器的内容。您可能会发现您发送的内容与实际需要的内容有所不同

于 2012-04-23T12:19:34.383 回答
0

检查网络服务的 URL 应该是http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit吗?或者

http://www.w3schools.com/webservices/tempconvert.asmx?op=FahrenheitToCelsius ??

于 2012-04-23T12:21:26.770 回答
0

尝试添加准备好的文档:

    jQuery.support.cors = true;
于 2012-04-23T12:10:52.677 回答