使用jQuery WITH JSON PARAMETER调用WCF服务 [英] Calling WCF Services using jQuery WITH JSON PARAMETER

查看:68
本文介绍了使用jQuery WITH JSON PARAMETER调用WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法通过参数解决JSON问题。



unable TO RESOLVE THE ISSSUE OF JSON WITH PARAMETER.

<script type="text/javascript">
        var Type;
        var Url;
        var Data;
        var ContentType;
        var DataType;
        var ProcessData;

        function WCFJSON() {
            debugger;
            var MobileNo = $("#txtMobileNo").val();
            var TokenID = $("#txtTokenNumber").val();

            //alert(Data);
            //   var JSONObject = { "GetClientDetailFromPrimary": { "tokenid": "" + TokenID + "", "MobileNo": "" + MobileNo + ""} };


            Type = "GET";
            //Url = "http://localhost:12344/SecondaryToPrimaryRESTful.svc/JSON/GetClientDetailFromPrimary/" + $("#txtTokenNumber").val() + "/" + $("#txtMobileNo").val();
            //  Url = "http://localhost:12344/SecondaryToPrimaryRESTful.svc/JSON/GetClientDetailFromPrimary/MobileID/09898345474";
            //
            Url = "http://localhost:12344/SecondaryToPrimaryRESTful.svc/JSON/GetClientDetailFromPrimary";
            Data = '{"tokenid": "' + TokenID + '","MobileNo":"' + MobileNo + '"}';
            // Data = '{"MobileNo":"' + MobileNo + '"}';

            //Data = JSON.stringify(Data);
            ContentType = "application/json; charset=utf-8";
            DataType = "json";
            ProcessData = true;
            CallService();
        }

        //function to call WCF  Service
        function CallService() {

            $.ajax({
                type: Type, //GET or POST or PUT or DELETE verb
                url: Url, // Location of the service
                data: Data, //Data sent to server
                contentType: ContentType, // content type sent to server
                dataType: DataType, //Expected data format from server
                processdata: ProcessData, //True or False
                success: function (msg) {//On Successfull service call
                    ServiceSucceeded(msg);
                },
                error: ServiceFailed// When Service call fails
            });
        }

        function ServiceFailed(result) {
            debugger;
            alert('Service call failed: ' + result.status + '' + result.statusText);
            Type = null; varUrl = null; Data = null; ContentType = null; DataType = null; ProcessData = null;
        }

        function ServiceSucceeded(result) {
            debugger;
            if (DataType == "json") {
                $('#<%=txtClientID.ClientID %>').val(result.client_id);
                $('#<%=txtFundID.ClientID %>').val(result.fund_id);
                $('#<%=txtClientName.ClientID %>').val(result.client_name);
                $('#<%=txtFundName.ClientID %>').val(result.fund_name);
                $('#<%=txtPrimaryName.ClientID %>').val(result.contact_name1);
                $('#<%=txtPrimaryContact.ClientID %>').val(result.contact_mobile1);
            }

        }

        function ServiceFailed(xhr) {

            alert(xhr.responseText);
            if (xhr.responseText) {
                var err = xhr.responseText;
                if (err)
                    error(err);
                else
                    error({ Message: "Unknown server error." })
            }
            return;
        }
        $(document).ready(function () {
            //
            $("#btnSubmit").click(function () {

                var mobileNo = $("#txtMobileNo").val();

                if (mobileNo == "") {
                    alert(">> Mobile No. cannot be blank.");
                } else {
                    WCFJSON();
                }
                return false;
            });
        });
    </script>

推荐答案

#txtMobileNo)VAL();
var TokenID =
("#txtMobileNo").val(); var TokenID =


#txtTokenNumber)VAL();

// alert(数据);
// var JSONObject = {GetClientDetailFromPrimary:{tokenid:+ TokenID +,MobileNo: + MobileNo +}};


类型= GET;
// Url =http:// localhost:12344 / SecondaryToPrimaryRESTful.svc / JSON / GetClientDetailFromPrimary / +
("#txtTokenNumber").val(); //alert(Data); // var JSONObject = { "GetClientDetailFromPrimary": { "tokenid": "" + TokenID + "", "MobileNo": "" + MobileNo + ""} }; Type = "GET"; //Url = "http://localhost:12344/SecondaryToPrimaryRESTful.svc/JSON/GetClientDetailFromPrimary/" +


(#txtTokenNumber)。val()+/+
("#txtTokenNumber").val() + "/" +


这篇关于使用jQuery WITH JSON PARAMETER调用WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆