简体   繁体   English

从html调用wcf服务总是会出错。 与aspx页面正常工作

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

I have created a simple webservice which is hosted in same domain. 我创建了一个简单的Web服务,该服务托管在同一域中。

Now, I have created two pages 现在,我创建了两个页面

1) Aspx page where I'll be calling that webservice and it works just fine. 1)我将在其中调用该Web服务的Aspx页面,它工作正常。 Code is pasted below: 代码粘贴在下面:

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

First Name: Last Name: 名:姓:

    $(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>

This thing works just fine.. 这个东西很好用..

2) I've tried using same javascript code for an simple HTML page (code as shown below) 2)我已经尝试过将相同的javascript代码用于简单的HTML页面(代码如下所示)

<!DOCTYPE html>

Employee Hub Employee Hub - A Basic Test Application 员工中心员工中心-基本测试应用程序

    </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>

for this case it always goes to error function. 在这种情况下,它总是进入错误功能。

Not sure what's going wrong here for error it only produces "object object" 不知道这里出了什么问题导致错误,它只会产生“对象对象”

Any help would be greatly appreciated. 任何帮助将不胜感激。

Update : I am still having this problem... and the problem area for this issue is only in AJAX call. 更新 :我仍然有此问题...,此问题的问题区域仅在AJAX调用中。 calling the URL otherwise works fine. 调用URL,否则效果很好。

Any help will be greatly appreciated.. 任何帮助将不胜感激..

Added source code link to repo this issue. 添加了源代码链接以解决此问题。

There is typo error in the source code you provided ,rename datatTypes to datatType 您提供的源代码中存在拼写错误, datatTypes datatType重命名为datatType

i have checked the code from the link you provided and it is working fine. 我已经从您提供的链接中检查了代码,并且工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM