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

  • Home
  • SEARCH
  • 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 9231391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:03:20+00:00 2026-06-18T06:03:20+00:00

Ok, so for some reason, my ajax call keeps failing even though the server

  • 0

Ok, so for some reason, my ajax call keeps failing even though the server is returning 200 with valid json. Here is the ajax call:

        $.ajax(
        {
            cache: false,
            type: "GET",
            url: "http://localhost:10590/api/entry",
            dataType: "application/json; charset=utf-8",
            success: function (result) {
                alert('HIT');
            },
            error: function (request, type, errorThrown) {
                alert('Fail' + type + ':' + errorThrown);
            }
        });

The error function is displaying blanks. Type says “error” but nothing after that. I’m trying to figure out why this would be happening???

Verified via fiddler, this is the json string that is being returned from the server:

{
  "EntryId":0,
  "EntryDate":"2012-12-14T18:10:48.2275967-07:00",
  "BodyWeight":207.00,
  "Bmi":0.0,
  "Fat":0.0,
  "Visceral":0.0,
  "MuscleMass":0.0
}

http://jsonlint.com/ agrees that this is valid json.

UPDATE:
adding the following before the ajax call gets it to work in IE but not chrome:

$.support.cors = true;
  • 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-18T06:03:21+00:00Added an answer on June 18, 2026 at 6:03 am

    The solution I ended up using was to request ‘jsonp’ from the server. In order to get my server to return jsonp, I had to create a custom formatter. i had a hard time finding a formatter for it since every post referred to Thinktecture, which wouldn’t compile for me. So here is what I ended up with:

    using System;
    using System.IO;
    using System.Net;
    using System.Net.Http.Formatting;
    using System.Net.Http.Headers;
    using System.Threading.Tasks;
    using System.Web;
    using System.Net.Http;
    using Newtonsoft.Json.Converters;
    
    namespace MyDomain.Common.Web.CustomFormatters
    {
    
        /// <summary>
        /// Handles JsonP requests when requests are fired with text/javascript
        /// </summary>
        public class JsonpFormatter : JsonMediaTypeFormatter
        {
    
            public JsonpFormatter()
            {
                SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"));
                SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/javascript"));
    
                JsonpParameterName = "callback";
            }
    
            /// <summary>
            ///  Name of the query string parameter to look for
            ///  the jsonp function name
            /// </summary>
            public string JsonpParameterName { get; set; }
    
            /// <summary>
            /// Captured name of the Jsonp function that the JSON call
            /// is wrapped in. Set in GetPerRequestFormatter Instance
            /// </summary>
            private string JsonpCallbackFunction;
    
    
            public override bool CanWriteType(Type type)
            {
                return true;
            }
    
            /// <summary>
            /// Override this method to capture the Request object
            /// </summary>
            /// <param name="type"></param>
            /// <param name="request"></param>
            /// <param name="mediaType"></param>
            /// <returns></returns>
            public override MediaTypeFormatter GetPerRequestFormatterInstance(Type type, System.Net.Http.HttpRequestMessage request, MediaTypeHeaderValue mediaType)
            {
                var formatter = new JsonpFormatter()
                {
                    JsonpCallbackFunction = GetJsonCallbackFunction(request)
                };
    
                // this doesn't work unfortunately
                //formatter.SerializerSettings = GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings;
    
                // You have to reapply any JSON.NET default serializer Customizations here    
                formatter.SerializerSettings.Converters.Add(new StringEnumConverter());
                formatter.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;
    
                return formatter;
            }
    
    
            public override Task WriteToStreamAsync(Type type, object value,
                                            Stream stream,
                                            HttpContent content,
                                            TransportContext transportContext)
            {
                if (string.IsNullOrEmpty(JsonpCallbackFunction))
                    return base.WriteToStreamAsync(type, value, stream, content, transportContext);
    
                StreamWriter writer = null;
    
                // write the pre-amble
                try
                {
                    writer = new StreamWriter(stream);
                    writer.Write(JsonpCallbackFunction + "(");
                    writer.Flush();
                }
                catch (Exception ex)
                {
                    try
                    {
                        if (writer != null)
                            writer.Dispose();
                    }
                    catch { }
    
                    var tcs = new TaskCompletionSource<object>();
                    tcs.SetException(ex);
                    return tcs.Task;
                }
    
                return base.WriteToStreamAsync(type, value, stream, content, transportContext)
                           .ContinueWith(innerTask =>
                           {
                               if (innerTask.Status == TaskStatus.RanToCompletion)
                               {
                                   writer.Write(")");
                                   writer.Flush();
                               }
    
                           }, TaskContinuationOptions.ExecuteSynchronously)
                            .ContinueWith(innerTask =>
                            {
                                writer.Dispose();
                                return innerTask;
    
                            }, TaskContinuationOptions.ExecuteSynchronously)
                            .Unwrap();
            }
    
            /// <summary>
            /// Retrieves the Jsonp Callback function
            /// from the query string
            /// </summary>
            /// <returns></returns>
            private string GetJsonCallbackFunction(HttpRequestMessage request)
            {
                if (request.Method != HttpMethod.Get)
                    return null;
    
                var query = HttpUtility.ParseQueryString(request.RequestUri.Query);
                var queryVal = query[this.JsonpParameterName];
    
                if (string.IsNullOrEmpty(queryVal))
                    return null;
    
                return queryVal;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

for some reason when I try to call CocoaAsyncSocket's onSocket:didReadData:withTag method, it's failing and
Possible Duplicate: jquery ajax call taking too long or something for some reason this
For some reason one particular AJAX call of mine is getting a No parameterless
Here is the json returned by an ajax call: { StumbleUpon: 0, Reddit: 0,
For some reason the ajax requests I make on the website I'm working on
I've implemented more complex AJAX before with javascript and PHP, but for some reason
For some reason, this line of code is returning undefined for $(this).attr(href) $(a).attr(href, javascript:page('
For some reason the postback event keeps firing for my button. If I place
I added a simple voting feature to my website. For some reason, the ajax
I am doing an ajax call using jquery to get data in json format.

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.