Click here to Skip to main content
11,922,320 members (39,259 online)
Rate this:
Please Sign up or sign in to vote.
I am trying to access the data from server(other domain).

I have a created a Webservice called hellojson.asmx which is in server


Webservice code:
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["test"].ConnectionString.ToString());
            string status = "";
            string userid = "";
            Dictionary<string,> oDict = new Dictionary<string,>();
            SqlCommand com = new SqlCommand("select userid from users where username='" + x + "' and password='" + y + "'", con);
            SqlDataReader dr;
            if (con.State == ConnectionState.Closed)
            dr = com.ExecuteReader();
            if (dr.Read())
                //userid = dr["UserId"].ToString();            
                status = "Login Success";
                SqlDataAdapter da = new SqlDataAdapter("select name from Employee", con);
                DataSet ds = new DataSet();
                object[] arr = new object[ds.Tables["employees"].Rows.Count + 1];
                for (int i = 0; i <= ds.Tables["employees"].Rows.Count - 1; i++)
                    arr[i] = ds.Tables["employees"].Rows[i].ItemArray;
                oDict.Add("employees", arr);
                status = "Login failed";
            JavaScriptSerializer js = new JavaScriptSerializer();
            return js.Serialize(status);

In Local host i have created a html file called login.html

<html xmlns="">
  <title>Login Page</title>
    <script src=""></script>
        <form method="get" action="#">
                <label for="Username"><em>* </em> Username: </label>
                <input type="text" id="Lusername" name="Username" class="required" />
                <label for="password"><em>* </em>Password: </label>
                <input type="password" id="Lpassword" name="password" class="required" />
            <div class="ui-block-a"><button data-theme="c">Cancel</button></div>
            <div class="ui-block-b"><button type="submit" data-theme="b">Submit</button></div>
In the javascript file

                contentType: "application/json; charset=utf-8",
                url: "",
                    dataType: 'jsonp',
                    // do stuff with json (in this case an array)
                    error: function(xmlHttpRequest, textStatus, errorThrown) {
I would like to display the result in alert box..but i am unable get the result pls help me..
Posted 12-Jun-12 0:41am
Edited 12-Jun-12 3:42am
Karthik. A 12-Jun-12 22:20pm
Looks like you are using the correct dataType parameter. What is the error thrown? Can you update / comment w/ the error that's thrown?
tanisha_forum 12-Jun-12 22:55pm
Hi karthik thanks for your reply..When i am using jsonp datatype its displaying an error "jquery 1234234345756544767 was not called". if i change the datatype as json instead of jsonp its showing an empty alert box..pls fix the problem what i am missing there
Karthik. A 12-Jun-12 23:10pm
I have added an answer, check it out...

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Looks like $.getJSON will be more helpful in this case. Refer this thread -[^] and this thread[^]. These 2 links might help you.

Update: I suddenly remembered seeing something like this, remote call here in this jsfiddle fiddle.[^], This uses the following jquery plugin:[^]

Hope this helps!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 493
1 Dave Kreskowiak 285
2 Sergey Alexandrovich Kryukov 243
3 Richard MacCutchan 155
4 ppolymorphe 135
0 OriginalGriff 7,231
1 KrunalRohit 4,530
2 Sergey Alexandrovich Kryukov 3,356
3 George Jonsson 2,865
4 Suvendu Shekhar Giri 2,216

Advertise | Privacy | Mobile
Web02 | 2.8.151120.1 | Last Updated 12 Jun 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100