Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi i am in problem with WCF with JSON it show nothing ....show undefined

JSON :

C#
function CallMyService() {
          $.ajax({
              type: "POST",
              url: "http://localhost:82/BookingRequest.svc/AutoSuggestBookPanel?prefixText=Australia&ReturnType=json",
              contentType: "application/json;charset-uf8", // content type sent to server
              dataType: "json", //Expected data format from server
              success: function (msg) {
                  alert(msg);
              },
              error: function (response, textStatus, errorThrown) {

                  alert(response.responseText);
                  alert(textStatus.responseText);
                  alert(errorThrown);
              }
          });
      }


.cs File
C#
[OperationContract]
      [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
          UriTemplate = "/AutoSuggestBookPanel?prefixText={prefixText}&ReturnType={ReturnType}")]
      String AutoSuggestBookPanel(String prefixText, String ReturnType);



please give me help......
Posted
Updated 4-Dec-13 0:04am
v3
Comments
Sampath Lokuge 4-Dec-13 6:06am    
Did you check the service is up and running ?
tbs.hardik 4-Dec-13 6:20am    
yes...its working fine....
Sampath Lokuge 4-Dec-13 6:23am    
Check whether is there any errors on the js post by using chrome dev tools ?
tbs.hardik 4-Dec-13 6:27am    
i have hosted this service in my local and its working properly.when i run this service in my browser by putting querystring value hard coded then it is giving me reply but when i call this function from my cross domain web page it gives me error...

1 solution

OP's Comment:

Quote:
i have hosted this service in my local and its working properly.when i run this service in my browser by putting querystring value hard coded then it is giving me reply but when i call this function from my cross domain web page it gives me error...



According to your comments you cannot test your WCF service that way.If you need to test it from cross domain then you have to host your service on Public IIS server.It won't work with the localhost the way you tried (i.e. url: "http://localhost:82/BookingRequest.svc/AutoSuggestBookPanel?prefixText=Australia&ReturnType=json", ).

So host your service on public IIS server and check after that by replacing that host url on above js method.
 
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