Reputation: 904
Below is my code in codebehind in asp.net web application, I have consumed another web service in this web application and evoked it's method as followed,
[WebMethod]
public static string GetData(string name)
{
WEBSERVICE.Service1 Client = new Service1();
string Name= Client.QPRST_Operation(name);
return Name;-------------//Want to pass this value in jquery function
}
I get the JSON format on String Name, , I want to call that string in my jquery function below,
<script type="text/javascript">
function asyncServerCall(Name) {
alert(Name);
jQuery.ajax({
url: 'WebForm1.aspx/GetData',
type: "POST",
data: "{'name':'" + Name + "'}",
contentType: "application/json",
dataType: "json",
success: function (data) {
alert(Name);
}
});
}
</script>
,
but I am not able to pass the string value to jquery function,in alert its giving SC.1938773693.238 this value... my main aim is to take those values any plot the charts in highcharts,
Below function works properly,
<script type="text/javascript">
function loadJson() {
$(document).ready(function () {
//alert("inside");
var chart;
var seriesData;
$.getJSON("val1.json", function (data) {
var chartoptions = data;
chartoptions.chart.renderTo = 'container';
chart = new Highcharts.Chart(chartoptions);
});
});
}
</script>
but in $.getJSON method..instead of val1.json I want values from the string returned from code behind and need to make a AJAX Call..actually I have tried above, I know the code is going to be error prone,
Since I am new to this concept any help will be greatly appreciated..
Upvotes: 0
Views: 1724
Reputation: 4364
Try this:
<script type="text/javascript">
function asyncServerCall(Name) {
alert(Name);
jQuery.ajax({
url: 'WebForm1.aspx/GetData',
type: "POST",
data: "{'name':'" + Name + "'}",
contentType: "application/json",
dataType: "json",
success: function (data) {
alert(data.d);
}
});
}
</script>
Upvotes: 0
Reputation: 13248
Change:
success: function (data) {
alert(Name);
}
To:
success: function (data) {
alert(data.d);
}
Upvotes: 1