-1

I have Written A Simple WCF Method.It is returning Correct values But It is showing 200

    $.ajax({
        url: "http://localhost:60770/Service.svc/GetContacts?calback=?",
        type: "POST",
        dataType: "JSON",
        contentType: "application/json",
        data: "{}",
        crossDomain: true,
        processdata: true,
        success: function (response) {
        //    var data = response;
            alert("data.FirstName");
        },

        error: function (e) {
            alert('error ' + e.status + ' ' + e.responseText);

        }
    });

It is going to error and when i am checking the response using FireBug. it is showing Json there.

Please Help!!

1 Answers1

0

It looks like you're mixing JSON and JSONP here.

You have crossDomain:true, absolute URL, but pointing to local host. Then you have typo in example ?calback=? (missing "l" and 2nd "?").

In JSONP your:

/GetContacts?calback=myFunction

you expect result like: myFunction({"d":"Hello"})

myFunction will be called automatically. In your case "?" is name of the function. And WCF, .NET 4 it supports JSONP, but you have to enable it: How to natively enable JSONP for existing WCF service?

So I would switch-off crossDomain:true and provide relative url without callback parameter, or read a bit on JSONP: What is JSONP all about?

Community
  • 1
  • 1
Nenad
  • 24,809
  • 11
  • 75
  • 93
  • Thanks for responding..i have Cross domain to use for example : www.example.com/Services.svc but things are not working so i created a service on my local.please guide me how to make it work with cross domain. – user1657868 Mar 09 '13 at 18:19
  • You have enough clues now to fix it. Just read read those 2 short articles yourself. ;) – Nenad Mar 09 '13 at 18:34