0

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..

1
  • alert(data.d); in place of alert(Name); Commented Nov 25, 2013 at 14:34

3 Answers 3

1

Change:

success: function (data) {
                alert(Name);
            }

To:

success: function (data) {
                alert(data.d);
            }
Sign up to request clarification or add additional context in comments.

3 Comments

What is the reason behind changing it to data.d or some have advised to change to response.d.. can you please explain the reason behind it?
And a SO post with more detail: stackoverflow.com/questions/6588589/…
0

You should change your success alert to: alert (response.d)

Comments

0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.