Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
unable TO RESOLVE THE ISSSUE OF JSON WITH PARAMETER.

C#
<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>
Posted
Updated 18-Mar-15 2:25am
v2
Comments
Sergey Alexandrovich Kryukov 18-Mar-15 8:30am    
And the issue is..?
—SA
yogesh kumar14 19-Mar-15 2:46am    
How to pass json data to wcf service and what to change to uritemplate

1 solution

You should use Type = "POST" when you are passing some data in body.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900