Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8828463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:36:43+00:00 2026-06-14T07:36:43+00:00

I’ve searched for this and I’ve not been able to find something that helps

  • 0

I’ve searched for this and I’ve not been able to find something that helps me so I appologise if this has been posted and I’ve just been unable to find it.

I’ve created a WCF service application that is being hosted in IIS. Presently its very basic with just a hello world method basically to return a country name and its code as a json object.

I’ve also written some jquery that will call the method remotely with the aim of populating list objects.

Currently when I call the method it hits the success paramater of the ajax call and alerts me with “undefined” I’ve no idea whats causing this but its most likely I’ve made a silly mistake.

Heres the code of the service and jquery

web config:

<configuration>

<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="None" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<standardEndpoints>
  <webScriptEndpoint>
    <standardEndpoint crossDomainScriptAccessEnabled="true"/>
  </webScriptEndpoint>
 </standardEndpoints>

</system.serviceModel>


</configuration>

service1.svc

<%@ ServiceHost Language="C#" Debug="true" Service="RestfulFlightWCF.Service1" codeBehind="Service1.svc.cs" Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory"  %>

service1.svc.cs
{
// NOTE: You can use the “Rename” command on the “Refactor” menu to change the class name “Service1” in code, svc and config file together.

[ServiceContract(Namespace = "JsonpAjaxService")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1 
{
    [WebGet(ResponseFormat = WebMessageFormat.Json)]
    public Country GetCountry(string id)
    {

       Country county = new Country();
        county.Name = "United Kingdom";
        county.Id = "gb";
        return county;
    }

    [DataContract]
    public class Country
    {
        [DataMember]
        public string Id { get; set; }

        [DataMember]
        public string Name { get; set; }
    }

}

jquery

    $(document).ready(
     function () {
        $.ajax({
            type:"GET",
            Data:'gb',
            Url:"http://192.168.1.6:80/FlightServices.svc/GetCountry",
            DataType:"jsonp",
            method:"GetCountry",
            success: function(msg){
                debugger;
                    alert(msg.responseText);
                        if (msg.responseText) {
                            var err = msg.responseText;
                            if (err)
                                error(err);
                            else
                                error({ Message: "Unknown server error." })
                        }
            },
            failure: function(){
                alert("something went wrong");
            },
            error: function(){
                alert("something happned");
            }
        });
         });

Sorry for the long post but I thought it would help if I included my code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:36:44+00:00Added an answer on June 14, 2026 at 7:36 am

    Ok So I got this working tonight after fiddling about for a while so I thought I’d post up some of the stuff that I found out whilst looking for the fix.

    1. Add in response format to the WebGet on the method being called.

      [WebGet(ResponseFormat= WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
      
    2. Changed my jQuery to the following:

      var Type;
      var Url;
      var Data;
      var ContentType;
      var DataType;
      var ProcessData;
      var method;
      //Generic 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 Successful service call
                  ServiceSucceeded(msg);
              },
              error: ServiceFailed// When Service call fails
          });
      }
      
      function ServiceFailed(xhr) {
          alert(xhr.responseText);
          if (xhr.responseText) {
              var err = xhr.responseText;
              if (err)
                  error(err);
              else
                  error({ Message: "Unknown server error." })
          }
          return;
      }
      
      function ServiceSucceeded(result) {
          if (DataType == "jsonp") {
      
                  debugger;
                  resultObject = result.GetEmployeeResult;
                  var string = result.Name + " \n " + result.Id ;
                  alert(string); 
          }
      }
      
      function GetCountry() {
          Data = {id : "us"};
          Type = "GET";
          Url = "http://192.168.1.6:80/FlightService.svc/GetCountry"; 
          DataType = "jsonp";
          ContentType = "application/json; charset=utf-8";
          ProcessData = false;
          method = "GetCountry";
          CallService();
      }
      
      $(document).ready(
       function () {
      
           GetCountry();
       }
      

    key point I found was passing the parameters down to the webGet method as

    data: {id : "gb"}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I know there's a lot of other questions out there that deal with this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.