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 7434539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:51:18+00:00 2026-05-29T09:51:18+00:00

I have been working on a JQuery script that posts JSON to my asp.net

  • 0

I have been working on a JQuery script that posts JSON to my asp.net web service. If the script is on the same domain it processes correctly but when I try to run the script from a local file or on an alternative domain not appears to happen to the eye!.. Though what I have noticed is that within my web logs the attempt is reaching the server but with the method OPTIONS rather than POST.

I have tried to set the following headers within IIS, web.config directly and within my global.asax file to on the application_beginRequest event but no success thus far!

Access-Control-Allow-Origin *

Access-Control-Allow-Methods GET, POST.

My global.asax file contain this:

protected void Application_BeginRequest(object sender, EventArgs e)
{

    HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
    HttpContext.Current.Response.Cache.SetNoStore();

    EnableCrossDmainAjaxCall();
}

private void EnableCrossDmainAjaxCall()
{
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");

    if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
    {
        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods",
                      "GET, POST, OPTIONS");
        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers",
                      "Content-Type, Accept");
        HttpContext.Current.Response.AddHeader("Access-Control-Max-Age",
                      "1728000");
        HttpContext.Current.Response.End();
    }
}

My client side script is as follows:

$.ajax({
            type: "POST",
            crossDomain: true,
            url: "http://myservice.mydomain.com/Data.asmx/Import",
            data: "{\"AppSession\":" + JSON.stringify(session) + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                // Insert the returned HTML into the <div>.
                $('#content').html(data.d);
            },
            error: function (j, t, e) {

                $('#content').html(e);
            }
        });

My web service code is as follows…

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;

/// <summary>
/// Summary description for DataMgt
/// </summary>
[WebService(Namespace = "DataManagement")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]

public class DataMgt : System.Web.Services.WebService {

    public DataMgt () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 

    }
    public class GeoData
    {
        public string GEOLongitude { get; set; }
        public string GEOLatitude { get; set; }
        public string GEOAccuracy { get; set; }
        public string GEOStatusID { get; set; }
    }

    public class AppSession
    {
        public GeoData GEOData { get; set; }
        public string UserID { get; set; }
        public string CountryID { get; set; }
    }

    [WebMethod]

    public string ImportData(AppSession AppSession)
    {
        string strStatusCode;
        try
        {
            //Do stuff here with requested data

            strStatusCode = "SUCCESS";
        }
        catch (Exception ex)
        {
            strStatusCode = "FAILURE";
        }

        return strStatusCode;

    } 
}

As I said earlier, this runs absolutely fine when the client side script is run on the same domain.

The website that hosts my service is on IIS 7 and ASP.NET 4.

Has anyone expereinced this when using a similar setup to me or can anyone suggest how to resolve this?

Many thanks in advance,

Rit

  • 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-05-29T09:51:19+00:00Added an answer on May 29, 2026 at 9:51 am

    If you working on diffrent domain you will not be able to POST request to your server. Its restricted, you have to use JSONP

    JSONP:
    http://api.jquery.com/jQuery.getJSON/

    A tutorial:
    http://abstractform.wordpress.com/2009/10/12/accessing-remote-asp-net-web-services-using-jsonp/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a asp.net mvc2 app. I have been using jquery to do
I have been working with Visual Studio (WinForm and ASP.NET applications using mostly C#)
I have been working on this script: <script type=text/javascript src=/js/jquery.js></script> <script type=text/javascript> $(function(){ compentecy
I've been working with ASP.NET MVC and Javascript/jQuery a lot lately and I seem
I have been working with the jQuery Grid the past few days and one
I have been working on a web services related project for about the last
I have been working with a string[] array in C# that gets returned from
I have been working on some legacy C++ code that uses variable length structures
I have some Ajax that has been working on a live site, now it
I am currently working on rails3 application that uses jQuery. I have a javascript

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.