Can not see the web service response in FlexBox

Jul 23, 2012 at 2:23 PM

Hi, i'm trying to fill my flexbox with a web service method from an aspx.

Here is the call to the web service:

        $(function() {
            
            $('#fb').flexbox('AgentService.asmx/GetAgents', {
                  method : 'post',
                  watermark: 'Type to search...',
                  width: 400,
                  onSelect: function() {
                      alert('You selected "' + this.value + '", ' +
                            'which has a hidden value of ' + this.getAttribute('hiddenValue'));
                  }
            });
            
        });

When I type a letter in the box, the Web method is executed, but it seems that the results are not being returned to the webpage

Here is my web service code:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class AgentService : System.Web.Services.WebService
{

  public AgentService()
  {

    //Uncomment the following line if using designed components 
    //InitializeComponent(); 
  }

  [WebMethod]
  public string GetAgents()
  {
    try
    {
      List<Agent> agents = new List<Agent>(workSession.SessionUser.Agents);
      agents.Sort(delegate(Agent a1, Agent a2)
                {
                  return a1.Name.CompareTo(a2.Name);
                });

      List<FlexboxItem> results = new List<FlexboxItem>(agents.Count);
      foreach (Agent agent in agents)
      {
        results.Add(new FlexboxItem(agent.Id.ToString(), agent.Name));
      }

      JavaScriptSerializer serializer = new JavaScriptSerializer();
      string s = "{\"results\": " + serializer.Serialize(results) + "}";
      return s;
    } // try
    catch (Exception)
    {
      throw;
    } // catch
  }
}

Is there anything i'm missing?. Thanks a lot!

Coordinator
Jul 23, 2012 at 8:20 PM

You mentioned that your code is being called. When you debug, does the result string contain what you expect it to?

I’m not seeing any code in your web method that grabs what the user typed in (which is available in query string parameter “q”), and searching based on that, but maybe you don’t need that.

Is your data getting serialized into a JavaScript array? Are the “id” and “name” properties being serialized to lowercase? They need to be…

Noah

From: gabay [email removed]
Sent: Monday, July 23, 2012 11:34 AM
To: Noah Heldman
Subject: Can not see the web service response in FlexBox [flexbox:387782]

From: gabay

Hi, i'm trying to fill my flexbox with a web service method from an aspx.

Here is the call to the web service:

        $(function() {
            
            $('#fb').flexbox('AgentService.asmx/GetAgents', {
                  method : 'post',
                  watermark: 'Type to search...',
                  width: 400,
                  onSelect: function() {
                      alert('You selected "' + this.value + '", ' +
                            'which has a hidden value of ' + this.getAttribute('hiddenValue'));
                  }
            });
            
        });

When I type a letter in the box, the Web method is executed, but it seems that the results are not being returned to the webpage

Here is my web service code:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class AgentService : System.Web.Services.WebService
{
 
  public AgentService()
  {
 
    //Uncomment the following line if using designed components 
    //InitializeComponent(); 
  }
 
  [WebMethod]
  public string GetAgents()
  {
    try
    {
      List<Agent> agents = new List<Agent>(workSession.SessionUser.Agents);
      agents.Sort(delegate(Agent a1, Agent a2)
                {
                  return a1.Name.CompareTo(a2.Name);
                });
 
      List<FlexboxItem> results = new List<FlexboxItem>(agents.Count);
      foreach (Agent agent in agents)
      {
        results.Add(new FlexboxItem(agent.Id.ToString(), agent.Name));
      }
 
      JavaScriptSerializer serializer = new JavaScriptSerializer();
      string s = "{\"results\": " + serializer.Serialize(results) + "}";
      return s;
    } // try
    catch (Exception)
    {
      throw;
    } // catch
  }
}

Is there anything i'm missing?. Thanks a lot!

Jul 24, 2012 at 1:00 PM

Hi Noah, thanks for answering.

The web service call is executed when I click the flexbox arrow. Here is the response.

"{\"results\":[{\"id\":\"29\",\"name\":\"Andreani Logistica SA  \"},{\"id\":\"33\",\"name\":\"AstraZeneca SA. \"},{\"id\":\"34\",\"name\":\"FARMACITY SA \"}]}"

For the moment i've solved it by calling the web service with the jquery object, like this

            $.ajax(
            {
              type: "POST",
              url: 'AgentService.asmx/GetAgents',
              success: function(data)
              {
                var json = $.parseJSON(data.text);
                $('#fb').flexbox(json,
                {
                  resultTemplate: '<div class="col1">{id}</div> <div class="col2">{name}</div>',
                  watermark: 'Type to search...',
                  width: 500,
                  onSelect: function()
                  {
                      alert('You selected "' + this.value + '", ' +
                            'which has a hidden value of ' + this.getAttribute('hiddenValue'));
                  }
                });
              }
            });

Then I had to parse the response to JSON, assign it to flexbox and it worked just fine.

Gabay.

 

nheldman wrote:

You mentioned that your code is being called. When you debug, does the result string contain what you expect it to?

 

I’m not seeing any code in your web method that grabs what the user typed in (which is available in query string parameter “q”), and searching based on that, but maybe you don’t need that.

 

Is your data getting serialized into a JavaScript array? Are the “id” and “name” properties being serialized to lowercase? They need to be…

 

Noah

 

From: gabay [email removed]
Sent: Monday, July 23, 2012 11:34 AM
To: Noah Heldman
Subject: Can not see the web service response in FlexBox [flexbox:387782]

 

From: gabay

Hi, i'm trying to fill my flexbox with a web service method from an aspx.

Here is the call to the web service:

        $(function() {
            
            $('#fb').flexbox('AgentService.asmx/GetAgents', {
                  method : 'post',
                  watermark: 'Type to search...',
                  width: 400,
                  onSelect: function() {
                      alert('You selected "' + this.value + '", ' +
                            'which has a hidden value of ' + this.getAttribute('hiddenValue'));
                  }
            });
            
        });

When I type a letter in the box, the Web method is executed, but it seems that the results are not being returned to the webpage

Here is my web service code:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class AgentService : System.Web.Services.WebService
{
 
  public AgentService()
  {
 
    //Uncomment the following line if using designed components  
    //InitializeComponent();  
  }
 
  [WebMethod]
  public string GetAgents()
  {
    try
    {
      List<Agent> agents = new List<Agent>(workSession.SessionUser.Agents);
      agents.Sort(delegate(Agent a1, Agent a2)
                {
                  return a1.Name.CompareTo(a2.Name);
                });
 
      List<FlexboxItem> results = new List<FlexboxItem>(agents.Count);
      foreach (Agent agent in agents)
      {
        results.Add(new FlexboxItem(agent.Id.ToString(), agent.Name));
      }
 
      JavaScriptSerializer serializer = new JavaScriptSerializer();
      string s = "{\"results\": " + serializer.Serialize(results) + "}";
      return s;
    } // try
    catch (Exception)
    {
      throw;
    } // catch
  }
}

Is there anything i'm missing?. Thanks a lot!