Reputation: 5620
I have created an android application using (Jquery & PhoneGap). The application works fine Now, I want to retrieve data from my ASP.NET Web Service.
html:
<html>
<head>
<meta charset="utf-8">
<title>My Friends</title>
<link href="Jquery-mobile/jquery.mobile-1.1.0.css" rel="stylesheet" type="text/css" />
<script src="Jquery-mobile/jquery-1.4.1.js" type="text/javascript"></script>
<script src="Jquery-mobile/jquery.mobile-1.1.0.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
//code to fetch data from webservice
alert($("#test").html());
});
</script>
</head>
<body>
</body>
</html>
asp.net web service
/// <summary>
/// Summary description for WebService1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 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 WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
Upvotes: 0
Views: 4892
Reputation: 654
this may be help you try this code
$.ajax({
type: "POST",
url: URL,
async: false,
contentType: "application/json; charset=utf-8",
dataType: "json",
jsonp: "onJSONPLoad",
jsonpCallback: "newarticlescallback",
crossDomain: "false",
beforeSend: function (xhr) {
},
error: function (request, status, error) {
console.log("Error In Web Service...." + request.responseText);
return false;
},
success: function (data) {
Result = data;
},
complete: function (xhr, status) {
}
});
Upvotes: 0
Reputation: 14382
First uncomment the following line in the service
.....
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
// uncomment this ^ ^
public class WebService1 : System.Web.Services.WebService
{
.....
To call the hello world method use jQuery.ajax
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: "WebService1.asmx/HelloWorld",
data: "{}",
success: function(msg){
$("body").append(msg.d); //will append "Hello world" to body tag
},
error: function () {
}
});
I would recommend you to us WCF REST services instead
Upvotes: 1
Reputation: 15861
may be some thing like this
$.ajax({
url: 'yourPage/yourstatiCmethod',
contentType: "application/json; charset=utf-8",
dataType: "json"
type: "POST",
data:"{}"
success: function(data) {
alert('Do your all fetching Service');
}
});
Upvotes: 1