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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:58:46+00:00 2026-05-31T23:58:46+00:00

I have created a web service which takes a username and password as parameters

  • 0

I have created a web service which takes a username and password as parameters and returns a list of children in JSON (the user is a Social Worker). The web service is hosted locally with IIS7. I am attempting to access the web service using javascript/jquery because it will eventually need to run as a mobile app.

I’m not really experienced with web services, or javascript for that matter, but the following two links seemed to point me in the right direction:

http://williamsportwebdeveloper.com/cgi/wp/?p=494

http://encosia.com/using-jquery-to-consume-aspnet-json-web-services/

This is my html page:

   <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true" CodeBehind="TestWebService.aspx.cs" Inherits="Sponsor_A_Child.TestWebService" %>
<asp:Content ID="Content1" ContentPlaceHolderID="stylesPlaceHolder" runat="server">

<script type="text/javascript" src="Scripts/jquery-1.7.1.js">
$(document).ready(function () { });

function LoginClientClick() {
    $("#query_results").empty();
    $("#query_results").append('<table id="ResultsTable" class="ChildrenTable"><tr><th>Child_ID</th><th>Child_Name</th><th>Child_Surname</th></tr>');
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "http://localhost/PhoneWebServices/GetChildren.asmx?op=GetMyChildren",
        data: '{ "email" : "' + $("#EmailBox").val() + '", "password": "' + $("#PasswordBox").val() + '" }',
        dataType: "json",
        success: function (msg) {
            var c = eval(msg.d);
            alert("" + c);
            for (var i in c) {
                $("#ResultsTable tr:last").after("<tr><td>" + c[i][0] + "</td><td>" + c[i][1] + "</td><td>" + c[i][2] + "</td></tr>");
            }
        }
    });
}

</script>

</asp:Content>


<asp:Content ID="Content2" ContentPlaceHolderID="contentPlaceHolder" runat="server">

    <div id="LoginDiv">
        Email: <input id="EmailBox" type="text" /><br />
        Password: <input id="PasswordBox" type="password" /><br />

        <input id="LoginButton" type="button" value="Submit" onclick="LoginClientClick()" />
    </div>

    <div id="query_results">
    </div>

</asp:Content>

And this is my web service code:

[WebMethod (Description="Returns the list of children for whom the social worker is responsible.")]
        public String GetMyChildren(String email,String password)
        {
            DataSet MyChildren=new DataSet();

            int ID=SocialWorkerLogin(email, password);
            if (ID > 0)
            {
                MyChildren = FillChildrenTable(ID);
            }
            MyChildren.DataSetName = "My Children"; //To prevent 'DataTable name not set' error

            string[][] JaggedArray = new string[MyChildren.Tables[0].Rows.Count][];
           int i = 0;
           foreach (DataRow rs in MyChildren.Tables[0].Rows)
           {
               JaggedArray[i] = new string[] { rs["Child_ID"].ToString(), rs["Child_Name"].ToString(), rs["Child_Surname"].ToString() };
               i = i + 1;
           }

           // Return JSON data
           JavaScriptSerializer js = new JavaScriptSerializer();
           string strJSON = js.Serialize(JaggedArray);
           return strJSON;
        }

I followed the examples in the provided links, but when I press submit, only the table headers appear but not the list of children. When I test the web service on it’s own though, it does return a JSON string so that part seems to be working. Any help is greatly appreciated 🙂

EDIT: Thanks to slash197 I discovered the problem. I get the error:

"XMLHttpRequest cannot load http://localhost/PhoneWebServices/GetChildren.asmx?op=GetMyChildren. Origin http://localhost:56018 is not allowed by Access-Control-Allow-Origin."

In Chrome’s console. I’m guessing this has something to do with the URL, but when I try that URL in my browser it works fine.

  • 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-31T23:58:47+00:00Added an answer on May 31, 2026 at 11:58 pm

    the problem with

    "XMLHttpRequest cannot load http://localhost/PhoneWebServices/GetChildren.asmx?op=GetMyChildren. Origin http://localhost:56018 is not allowed by Access-Control-Allow-Origin."
    

    is, localhost and localhost:56018 are per definition two different domains, and Ajax Requests are per default only possible through the same domain.

    A best approach for that would be, to run both services on the same port or by using a proxy, which delivers the content from port 56018 to the default localhost port 80. Could be realized through a Rewrite Rule or via an own service which is running, besides your webservice “client”.

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

Sidebar

Related Questions

I have created a web service which returns some data and am trying to
I have created a web service in WCF which returns more than 54000 data-rows
I have created a web service which has a couple of methods developed using
I have created a web service which is saving some data into to db.
I have created a RESTful PHP web service using Lithium which contains comments, each
I have a web service in which I created an enum.. i have a
I have created a dummy web service with 2 optional parameters using the .Net
I have a web service method in which I create a particular type of
I have created Web-Service in asp.net with c# . Now i want to pass
I have created an web service I need to publish this service. I need

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.