0

I have created one wcf and is running locally in my machine. In the same project i have created a html page calling this wcf web service using ajax.

 $.ajax({
    type: "POST",
    url: "wbsvc.svc/calendar",
    contentType: "application/json; charset=utf-8",
    dataType: "jsonp",
    processData: false,
    success: function (msg) {
        var data = msg.d;
        console.log(data);
    },
    error: function (msg) {
        console.log(msg);
    }
});

calendar is the method in webservice. Error is

Failed to load resource: the server responded with a status of 400 (Bad Request) in wcf using ajax http://localhost:65029/wbsvc.svc/calendar?callback=jQuery110108707461392041296_1379052209564

What i am missing here.

Interface is

    [OperationContract]
    [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    Model.calenderinfo[] calendar();
4
  • You should post your service code, service configuration etc. if you want help. You are also using the POST method, but you don't include any data. Commented Sep 13, 2013 at 6:07
  • Its means you are not passing Parameter or some required resource Commented Sep 13, 2013 at 6:09
  • It's still better to use "GET" in your case, since you only query for an array of calendar info objects Commented Sep 13, 2013 at 8:25
  • you can see my answer here, this will give idea of different ways of doing call to wcf from jquery, one of those will surely suit you. stackoverflow.com/a/18735160/2206468 Commented Sep 13, 2013 at 13:01

2 Answers 2

0

jsonp is for crossDomain, just try json

Sign up to request clarification or add additional context in comments.

6 Comments

I'm not experienced in svc, but are you sure that it returns result in json format?
how can i check this...even i have not worked on svc earlier...i used to work on asmx
Well, before setting dataType into json just try it as html,and make success: function(msg) {alert(msg);} If it works, it means that problem is in formatting $.ajax({ url: "wbsvc.svc/calendar", dataType: "html", success: function (msg) { alert(msg); }, error: function (msg) { console.log(msg); } });
Still says Failed to load resource: the server responded with a status of 400 (Bad Request) in wcf using ajax localhost:65029/wbsvc.svc/… ?
have you tried to enter localhost:65029/wbsvc.svc/calendar page with browser? If your browser can't open this page, it means that you have to learn svc better
|
0

Change the datatype to Json.

dataType: "json"

I think the url for your wcf service is worng. Before sending the request, try to open Chrome Developer tool, or Firbug on Firefox, you can see the Request URL.

Now if your request URL is http://localhost/myproject/wbsvc.svc/calendar then type in http://localhost/myproject/wbsvc.svc in browser , if you are able to see the WSDL page, then your URL is correct. Otherwise you need to give correct url in URL parameter.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.