-->

Consuming WCF / REST service using JQuery ajax pos

2020-07-18 11:24发布

问题:

I am trying to post the data usign $.ajax, but I am getting failure message 400 error. Following is the code:

 $.ajax({

                url: "http://192.168.1.9:150/Service.svc/usrregistration",
                type: "POST",
                // data: '{"Firstname":' + Firstname + ',"LastName:"'+LastName+'}',
                data: '{"Firstname":"rose"}',

                contentType: "application/json; charset=utf-8",
                dataType: "json",
                processdata: true,
                success: function (msg) {
                    alert(msg);

                    alert('Registerd successfully');
                },
                error: function (msg) {

                    alert('Faild'+msg.status);
                }

            });

回答1:

here is my blog post for you : Create REST service with WCF and Consume using jQuery

REST service with WCF and Consume using jQuery by post you can figure out the problem easily its just 2 or 3 min walk though

Others

Steps to Call WCF Service using jQuery

Calling Cross Domain WCF service using Jquery/Javascript