Board index   FAQ   Search  
Register  Login
Board index php forum :: HTML JavaScript

php ajax call not working quite right

Javascript coding ..

Moderators: macek, egami, gesf

php ajax call not working quite right

Postby dot » Wed Sep 19, 2012 7:24 am

I'm just new to ajax and I'm having some trouble getting results to display when the controller is returning an emtpy array.
What I'm trying to accomplish is to display a combo box when the user clicks on a control called L1Locations.
If it's an empty array, I don't want to display a box at all. But right now, it always displays a combo box.
Can you tell me where I'm going wrong?

the output i get from my controller looks like this:

({'2.5':"Admin1", '2.10':"Admin2"})

and where it's an empty array,
the data is simply:

[]

Here's the code:
Code: Select all
<script>

$(document).ready(function(){
    $('#search').hide();
  });

$('#L1Locations').live('change',function(){

      var htmlstring;
      $selectedvalue = $('#L1Locations').val();

      $.ajax({
                url:"<?php echo site_url('switches/getbuildings/');?>" + "/" + $selectedvalue,
                type:'GET',
                dataType:'json',
                success: function(returnDataFromController) {
                    alert('success');
                        var htmlstring;
                        htmlstring="<select name='L2Locations' id='L2Locations'>";
                        htmlstring = htmlstring + "<option value='all'>All</option>";

                        console.log(returnDataFromController);


                         var JSONdata=[returnDataFromController];
                        alert('string length is' + JSONdata.length);
                        if(JSONdata.length > 0)
                        {
                            for(var i=0;i<JSONdata.length;i++){
                            var obj = JSONdata[i];
                              for(var key in obj){
                                     var locationkey = key;
                                     var locationname = obj[key];
                                     htmlstring = htmlstring + "<option value='" + locationkey + "'>" + locationname + "</option>";
                                }
                             }

                            $('#l2locations').html(htmlstring);

                        }
                        else
                        {
                            alert('i think undefined');
                            $('#l2locations').html('');
                        }                           
               }

    });
 $('#search').show();
 });
</script>
dot
New php-forum User
New php-forum User
 
Posts: 1
Joined: Wed Sep 19, 2012 7:17 am

mens burberry Burberry Outlet Online Sale (70)

Postby sherman79 » Tue Jun 04, 2013 11:22 am

There are specific home decoration ideas. First of all keep home simple and all the things must be kept as uncluttered. Rooms should be clean and functional. All the rooms should be easy to access. All the electronics burberry kids clothing in the home should have space between them and must be burberry boys clothing streamlined. Window coverings must lightly colored and airy. Plaster of Paris can be used to redecorate Sliding windows can be installed at bedrooms which burberry baby clothes will give picturesque view of the surroundings. Alternatively large windows can be installed for better ventilation and for filtering sunlight.
Bedroom Decoration requires ingenuity. Floor of bedroom should be inspiring and should give better look and feel. Marble flooring must be used for Villas. If bedrooms are large then wooden flooring must be used. Flooring can be changed to give home a new look. There can be a queen sized bed [url]burberry clothes men[/url] or a low bed along with the study table along with couches and tea table. Wooden furniture, Wardrobe and showcases made of wood can make home more valuable. To make bedrooms serene and soothing use fresh flowers and fragrant candles arranged burberry golf clothing in Japanese style. In addition grass wall hanging along with wooden surfaces and matte wall colors will give a rural look to the rooms. Color Platte of the bedrooms should be chosen burberry clothes for women which wouldn?t make bore ultimately. It should develop an enjoying mood. Superhero is the best theme for boy?s bedroom curtains where as fairytale is best for girl?s bedroom curtain. However colorful butterflies? curtains are the best for child?s bedroom. Beaded bed sheets with colorful pillows and cushions can add luxury to bedrooms.
Kitchen decoration is an important part of home decoration. Corners of the kitchen must be decorated with handicrafts and special centerpieces can be placed on the dining table. Hanging beautiful clock along with wall hangings or wall paintings can be used in kitchen. All accessories must be of same color. Paintings can be pasted on cabinets and place artificial plants on suitable places.

Related articles:


discount burberry Burberry Outlet Online Sale (58)

burberry jeans Burberry Outlet Online Sale (54)

burberry baby sale Burberry Outlet Online Sale (61
sherman79
New php-forum User
New php-forum User
 
Posts: 85
Joined: Mon Jan 07, 2013 12:01 pm


Return to JavaScript

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron