Jquery无法调用webservice

时间:2012-04-23 12:09:27

标签: jquery ajax jquery-mobile

我正在尝试使用Jquery AJAX调用webservice 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>

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

3 个答案:

答案 0 :(得分:0)

尝试添加文档就绪:

    jQuery.support.cors = true;

答案 1 :(得分:0)

使用Fiddler之类的工具检查实际请求发送到服务器的内容。您可能会发现您发送的内容与实际需要的内容存在差异

答案 2 :(得分:0)