Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8227633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:11:23+00:00 2026-06-07T16:11:23+00:00

I need to return an array of string from MyMethod at codebehind. But do

  • 0

I need to return an array of string from MyMethod at codebehind. But do I parse it on aspx page using javascript?

[WebMethod]
public static string[] MyMethod(){
   return new[] {"fdsf", "gfdgdfgf"};
}

..........
function myFunction() {
            $.ajax({ ......
                    success: function (msg) {
                                //how do I parse msg?
                                }
            });
        };
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T16:11:25+00:00Added an answer on June 7, 2026 at 4:11 pm

    First, make sure you’ve tagged your class with [ScriptService] to allow it to be called through AJAX. Something like:

    [ScriptService] //<-- Important
    public class WebService : System.Web.Services.WebService
    {
       [ScriptMethod] //<-- WebMethod is fine here too
       public string[] MyMethod()
       {
          return new[] {"fdsf", "gfdgdfgf"};
       }
    }
    

    You can then read the result with jQuery directly, as there’s no need to parse anything:

    $(document).ready(function() {
      $.ajax({
        type: "POST",
        url: "WebService.asmx/MyMethod",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
          // msg.d will be your array with 2 strings
        }
      });
    });
    

    Another approach is to just include a reference to:

    <script src="WebService.asmx/js" type="text/javascript"></script>
    

    This will generate proxy classes to allow you to call web methods directly. For example:

    WebService.MyMethod(onComplete, onError);
    

    The onComplete function will receive a single parameter with the results of the web service call, in your case a Javascript array with 2 strings. In my opinion, this is an easier solution than using jQuery and worrying about the URL and HTTP payload.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to return an array in php and use it in javascript. When
I need to return multiple STRING values from my backgroundworker in each loop, so
I need PHP code which will return an array with the player's stats, from
I would like to return an array of strings from C to Java using
I need to store a char array inside a class and then return it.
I need the following logic. If array contains value , return it else return
I need to return a list of counties, but I need to filter out
I need to return server time from a webservice. I've got the following code:
I need to return a string in the form xxx-xxxx where xxx is a
I'm using php to return an array of data, with the command json_encode() .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.