簡體   English   中英

從html調用wcf服務總是會出錯。 與aspx頁面正常工作

[英]calling wcf service from html always goes to error function. Works fine with aspx page

我創建了一個簡單的Web服務,該服務托管在同一域中。

現在,我創建了兩個頁面

1)我將在其中調用該Web服務的Aspx頁面,它工作正常。 代碼粘貼在下面:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>

名:姓:

    $(function () {

        $("#btnSayHello").click(function () {

            var txtFirstName = $("#MainContent_txtFirstName").val();
            var txtSecondName = $("#MainContent_txtLastName").val();
            $("#MainContent_lblResult").html("Hello " + txtFirstName + " " + txtSecondName);

            $.ajax({
                type: "GET",
                contentType: "json",
                datatTypes: "json",
                url: "http://10.24.104.196/TestServiceCore.svc/GetName/",
                success: function (data) {
                    alert(data);
                }
            });
        })
    });

</script>

這個東西很好用..

2)我已經嘗試過將相同的javascript代碼用於簡單的HTML頁面(代碼如下所示)

<!DOCTYPE html>

員工中心員工中心-基本測試應用程序

    </section>
</form>
<input id="btnSayHello" type="button" value="Get Value From WCF" /><br />
<label for="male" id="lblResult">Test</label>
<script type="text/javascript">
    $(function () {

        $("#btnSayHello").click(function () {
            $.ajax({
                type: "GET",
                contentType: "json",
                datatTypes: "json",
                url: "http://10.24.104.196/TestServiceCore.svc/GetName/",
                success: function (data) {
                    alert("Success");
                },
                error: function (result) {
                    //alert('error; ' + eval(result));
                    window.alert("eRROR");
                }
            });
        })
    });
</script>

在這種情況下,它總是進入錯誤功能。

不知道這里出了什么問題導致錯誤,它只會產生“對象對象”

任何幫助將不勝感激。

更新 :我仍然有此問題...,此問題的問題區域僅在AJAX調用中。 調用URL,否則效果很好。

任何幫助將不勝感激..

添加了源代碼鏈接以解決此問題。

您提供的源代碼中存在拼寫錯誤, datatTypes datatType重命名為datatType

我已經從您提供的鏈接中檢查了代碼,並且工作正常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM