I am trying to access the data from server(other domain).
I have a created a Webservice called hellojson.asmx which is in server
Ex: www.example.com/services/JsonWeb.asmx
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)
con.Open();
dr = com.ExecuteReader();
if (dr.Read())
{
dr.Close();
con.Close();
status = "Login Success";
SqlDataAdapter da = new SqlDataAdapter("select name from Employee", con);
DataSet ds = new DataSet();
da.Fill(ds,"employees");
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);
}
else
{
dr.Close();
con.Close();
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="http://www.w3.org/1999/xhtml">
<head>
<title>Login Page</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
</head>
<body>
<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>
</body>
</html>
In the
javascript file
$.ajax({
contentType: "application/json; charset=utf-8",
url: "www.example.com/services/JsonWeb.asmx",
dataType: 'jsonp',
success:function(json){
alert("Success");
},
error: function(xmlHttpRequest, textStatus, errorThrown) {
alert(errorThrown);
}
});
I would like to display the result in alert box..but i am unable get the result pls help me..