【问题标题】:How to call wcf webservice json using jquery?如何使用 jquery 调用 wcf webservice json?
【发布时间】:2013-10-01 06:31:09
【问题描述】:

我正在调用登录网络服务。但我无法检查我将从服务器获得什么。我喜欢这样吗? 这是我的网址和参数

这是我的尝试 http://jsfiddle.net/LsKbJ/2/

$(document).ready(function () {
        //event handler for submit button
        $("#btnSubmit").click(function () {
            //collect userName and password entered by users
            var userName = $("#username").val();
            var password = $("#password").val();

            //call the authenticate function
            authenticate(userName, password);
        });
    });

    //authenticate function to make ajax call
    function authenticate(userName, password) {
       $.ajax
    ({
        type: "POST",
        //the url where you want to sent the userName and password to
        url: "http://ii.c-cc.de/pp/REST",
        dataType: 'json',
        async: false,
        crossDomain: true,
        //json object to sent to the authentication url
        data: {Username: userName, Password: password},
        success: function () {
            //do any process for successful authentication here
        }
    })
    }

【问题讨论】:

  • 您的端点为 POST 请求返回 404。
  • 尝试使用 ,error:function(data){alert(data)}
  • yes ...这意味着找不到服务器。但是服务器正在运行..
  • 您使用的网址是否正确? (我的意思是“CentronService/REST”部分)
  • 是的,我的朋友给出了这个网址

标签: jquery json wcf web-services


【解决方案1】:

我建议您创建 REST api 以使用 WCF 获取和发布数据

【讨论】:

    【解决方案2】:

    我认为您错过了服务 URL 中的方法名称 MyMethodName。 还要确保控制台中没有跨源错误。 您可以从服务 url 的 help page 获取方法列表。

    //验证函数进行ajax调用

    url: "http://isuite.c-entron.de/CentronService/REST/MyMethodName",
    

    示例: url: http://isuite.c-entron.de/CentronService/REST/GetLoggedInUser

    将上述验证方法的url中的MyMethodName替换为适当的方法名称。

    【讨论】:

    • isuite.c-entron.de/CentronService/REST/help/operations/Login
    • 为了修复跨域 ajax 请求,您需要在响应标头中添加 AccessControlAlowOrigin。 cypressnorth.com/programming/…
    猜你喜欢
    • 2011-09-06
    • 2011-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-23
    相关资源
    最近更新 更多