jQuery Plugins » JSON https://jqueryplugins.info jQuery plugins, tutorials and resources Fri, 21 Oct 2011 19:13:58 +0000 en hourly 1 http://wordpress.org/?v=3.2.1 Accesing nested JSON items with JQuery https://jqueryplugins.info/2011/10/accesing-nested-json-items-with-jquery/ https://jqueryplugins.info/2011/10/accesing-nested-json-items-with-jquery/#comments Wed, 19 Oct 2011 19:13:48 +0000 Admin https://jqueryplugins.info/2011/10/accesing-nested-json-items-with-jquery/ Post link: Accesing nested JSON items with JQuery

I’ve been messing around with some aproaches, but haven’t succeeded, I’ve succesfully parsed JSON data before using JQuery but now I just can’t figure it out. With this code, $...

]]>
Post link: Accesing nested JSON items with JQuery

I’ve been messing around with some aproaches, but haven’t succeeded, I’ve succesfully parsed JSON data before using JQuery but now I just can’t figure it out.

With this code,

$  .each(data, function(headers, item){
    $  .each(item, function(){
        console.log(item[i].date_c);
        i++;
    });
});

I can easily read all dates of a JSON object like this one:

enter image description here

But right now I don’t know how to reach that date on a JSON object like this one:
enter image description here

As you can see, there’s a new level. Could you help me out?

Thanks in advance!

newest questions tagged jquery – Stack Overflow

]]>
https://jqueryplugins.info/2011/10/accesing-nested-json-items-with-jquery/feed/ 0
Retrieving data with PHP and Json into an autocomplete. Problems with jQuery UI 1.8.2+ https://jqueryplugins.info/2011/10/retrieving-data-with-php-and-json-into-an-autocomplete-problems-with-jquery-ui-1-8-2/ https://jqueryplugins.info/2011/10/retrieving-data-with-php-and-json-into-an-autocomplete-problems-with-jquery-ui-1-8-2/#comments Wed, 19 Oct 2011 12:14:58 +0000 Admin https://jqueryplugins.info/2011/10/retrieving-data-with-php-and-json-into-an-autocomplete-problems-with-jquery-ui-1-8-2/ Post link: Retrieving data with PHP and Json into an autocomplete. Problems with jQuery UI 1.8.2+

I made a movie autocomplete of which you type a letter and it gives you a suggest list of movies. Next to each movie I also added the date the...

]]>
Post link: Retrieving data with PHP and Json into an autocomplete. Problems with jQuery UI 1.8.2+

I made a movie autocomplete of which you type a letter and it gives you a suggest list of movies. Next to each movie I also added the date the movie was released.

This is how I parse it in PHP:

$  tmdb = new TMDb($  api_key);
$  json = json_decode($  tmdb->searchMovie($  _GET['term']));
$  response = array();
$  i=0;
foreach($  json as $  movie){
    if($  i >= 6) break;
    $  response[$  i]['value'] = $  movie->name;
    $  response[$  i]['label'] = $  movie->name . ' <span class="m_rel">(' . date('Y',strtotime($  movie->released)).')</span>';

    $  i++;
}
echo json_encode($  response);

Now, if I use jQuery 1.8.2 everything works perfectly.

I get this result:

enter image description here

Where if I use a later version of the jQuery UI I get this:

enter image description here

The html is simple, its just a form and the autocomplete its the one from the jQuery so nothing fancy. Once I change the version of the UI, the problem happens.

Could someone please help me on how can I solve this issue? I can’t use jQuery 1.8.2 because I’m getting other problems with draggable and IE (all versions) which cant be solved since its a known bug.

Thanks alot

newest questions tagged jquery – Stack Overflow

]]>
https://jqueryplugins.info/2011/10/retrieving-data-with-php-and-json-into-an-autocomplete-problems-with-jquery-ui-1-8-2/feed/ 0
Issue displaying individual JSON data value https://jqueryplugins.info/2011/10/issue-displaying-individual-json-data-value/ https://jqueryplugins.info/2011/10/issue-displaying-individual-json-data-value/#comments Tue, 18 Oct 2011 02:13:54 +0000 Admin https://jqueryplugins.info/2011/10/issue-displaying-individual-json-data-value/ Post link: Issue displaying individual JSON data value

In my php file I have: $ data = array(); while ($ row = mysql_fetch_array($ result, true)) {$ data[] = $ row;}; echo json_encode($ data); It produces the JSON array:...

]]>
Post link: Issue displaying individual JSON data value

In my php file I have:
$ data = array();
while ($ row = mysql_fetch_array($ result, true))
{$ data[] = $ row;};
echo json_encode($ data);

It produces the JSON array:
[{"record_id":"4","eq_type_id":"999","scidiv_id_tag":"AKINS04","date_last_updated":"2011-07-11 14:41:58","description":"Optics Table D","eq_type_desc":"Other Equipment Type"}]

In my JQUERY script:
$ (‘#output1′).html(data); displays the above array on my web page….

But both
$ (‘#output’).html(“Record Id: “+ data.record_id+”Eq Type ID: “+ data.eq_type_id);
and
$ (‘#output’).html(“Record Id: “+ data[0].record_id+”Eq Type ID: “+ data[1].eq_type_id);

Gives me

id: undefined name: undefined

Can someone tell me what I’m missing??

Thanks
Chris

newest questions tagged jquery – Stack Overflow

]]>
https://jqueryplugins.info/2011/10/issue-displaying-individual-json-data-value/feed/ 0
How to extract this json? https://jqueryplugins.info/2011/10/how-to-extract-this-json/ https://jqueryplugins.info/2011/10/how-to-extract-this-json/#comments Mon, 17 Oct 2011 23:13:39 +0000 Admin https://jqueryplugins.info/2011/10/how-to-extract-this-json/ Post link: How to extract this json?

I have a result like this {"Errors":{"Failure":{"ShowAsPopup":true,"ErrorMessage":"Some Message.","PopupTitle":null}},"IsValid":false,"WarningMessage":null,"SuccessMessage":null} now if I do Errors.Failure.ShowAsPopup I get a value. What is expected. However I want to use index instead(if that is possible)...

]]>
Post link: How to extract this json?

I have a result like this

{"Errors":{"Failure":{"ShowAsPopup":true,"ErrorMessage":"Some Message.","PopupTitle":null}},"IsValid":false,"WarningMessage":null,"SuccessMessage":null}

now if I do Errors.Failure.ShowAsPopup I get a value. What is expected. However I want to use index instead(if that is possible)

I tried

Errors[0].Failure.ShowAsPopup but this just gives me undefined. Ideal I would like to have it like Errors[0].[0].ShowAsPopup where I don’t have to specify the “Failure” but I might have to rethink that part.

I want a generic way to handle my errors. See some errors require a popup and some are just validation errors. So right now I have them all hardcoded and I am trying to get away from that. I rather just check if that error requires a popup or not.

So instead of

if(response.Errors.Failure) { // alert('hi')};
else if(response.Errors.Failure2 {// alert('hi2')}

and so on I would just have one if statement that could do the check.

newest questions tagged jquery – Stack Overflow

]]>
https://jqueryplugins.info/2011/10/how-to-extract-this-json/feed/ 0
How do I return arbitrary JSON objects to a jQuery Autocomplete list? https://jqueryplugins.info/2011/10/how-do-i-return-arbitrary-json-objects-to-a-jquery-autocomplete-list/ https://jqueryplugins.info/2011/10/how-do-i-return-arbitrary-json-objects-to-a-jquery-autocomplete-list/#comments Sun, 16 Oct 2011 13:14:47 +0000 Admin https://jqueryplugins.info/2011/10/how-do-i-return-arbitrary-json-objects-to-a-jquery-autocomplete-list/ Post link: How do I return arbitrary JSON objects to a jQuery Autocomplete list?

I have a jQuery UI 1.8 Autocomplete form that fetches remote JSON data from a Rails controller. $ ('input#test').autocomplete({ source: function( request, response ) { $ .getJSON( "<%= find_stuff_url(:format =>...

]]>
Post link: How do I return arbitrary JSON objects to a jQuery Autocomplete list?

I have a jQuery UI 1.8 Autocomplete form that fetches remote JSON data from a Rails controller.

$  ('input#test').autocomplete({
    source: function( request, response ) {
      $  .getJSON(
        "<%= find_stuff_url(:format => :json) %>",
        request,
        function(data){
          console.log(data);
      });
    },
    minLength: 2,
    select: function( event, ui ) {
        // ...
    }
  });

This Rails controller just returns an array of Objects (actually, ActiveRecord instances), serialized into JSON. I would like to use this data to populate the Autocomplete list. Right now, what I receive is an array of serialized ActiveRecord objects – for example one of these objects could be:

Object
control_point: Object
created_at: null
geonames_uri: "http://sws.geonames.org/5128581/"
label: "New York (US)"
lat: "40.7142691"
lng: "-74.0059729"
map_id: 1
name: "New York City"
updated_at: null
user_id: null
x: null
y: null

However, jQuery Autocomplete probably wants a JSON array of objects that carry id and label to populate its list — yet I don’t have these. This is what the documentation says:

A response callback, which expects a single argument to contain the data to suggest to the user. This data should be filtered based on the provided term, and can be in any of the formats described above for simple local data (String-Array or Object-Array with label/value/both properties).

I’m rather new to Javascript, and I don’t quite understand what’s meant by “String-Array or Object-Array with label/value/both” properties.

How do I pass an arbitrary JSON object to jQuery Autocomplete, so it shows a list of results? More explicitly: What do I have to put in function(data){}?

newest questions tagged jquery – Stack Overflow

]]>
https://jqueryplugins.info/2011/10/how-do-i-return-arbitrary-json-objects-to-a-jquery-autocomplete-list/feed/ 0
Parse json from Yahoo pipes using jquery/ javascript https://jqueryplugins.info/2011/10/parse-json-from-yahoo-pipes-using-jquery-javascript/ https://jqueryplugins.info/2011/10/parse-json-from-yahoo-pipes-using-jquery-javascript/#comments Sat, 15 Oct 2011 13:13:50 +0000 Admin https://jqueryplugins.info/2011/10/parse-json-from-yahoo-pipes-using-jquery-javascript/ Post link: Parse json from Yahoo pipes using jquery/ javascript

This is the format of the json that I get from Yahoo pipes. {"count":3, "value":{ "title":"Freak count feed", "description":"Pipes Output", "link":"http:\/\/pipes.yahoo.com\/pipes\/pipe.info?_id=565sdf6as5d4fasdac94835f", "pubDate":"Sat, 15 Jan 2011 05:53:12 -0320", "generator":"http:\/\/pipes.yahoo.com\/pipes\/","callback":"", "items":[ {"title":"photos...

]]>
Post link: Parse json from Yahoo pipes using jquery/ javascript

This is the format of the json that I get from Yahoo pipes.

 {"count":3,
        "value":{
            "title":"Freak count feed",
            "description":"Pipes Output",
            "link":"http:\/\/pipes.yahoo.com\/pipes\/pipe.info?_id=565sdf6as5d4fasdac94835f",
            "pubDate":"Sat, 15 Jan 2011 05:53:12 -0320",
            "generator":"http:\/\/pipes.yahoo.com\/pipes\/","callback":"",
            "items":[
                {"title":"photos count",
                "y:title":"photos count",
                "description":"6"},
                {"title":"videos count",
                "y:title":"videos count",
                "description":"null"},
                {"title":"blogs count",
                "y:title":"blogs count",
                "description":"7"}
                ]
                            }
        }

I have the Yahoo pipes url. How do i parse the json from the url using jquery to get the count from the ‘description’ for each content type?

newest questions tagged jquery – Stack Overflow

]]>
https://jqueryplugins.info/2011/10/parse-json-from-yahoo-pipes-using-jquery-javascript/feed/ 0
Ajax not processing JSON response https://jqueryplugins.info/2011/10/ajax-not-processing-json-response/ https://jqueryplugins.info/2011/10/ajax-not-processing-json-response/#comments Sat, 15 Oct 2011 04:14:41 +0000 Admin https://jqueryplugins.info/2011/10/ajax-not-processing-json-response/ Post link: Ajax not processing JSON response

In my app, a user can accept or decline a friend request. If you accept the request, my controller returns this JSON: {"icon":"<i class=\"friend_icon\" title=\"You're friends!\"><\/i>","response":"accept"} If you decline, this...

]]>
Post link: Ajax not processing JSON response

In my app, a user can accept or decline a friend request.

If you accept the request, my controller returns this JSON:

{"icon":"<i class=\"friend_icon\" title=\"You're friends!\"><\/i>","response":"accept"}

If you decline, this is the JSON response:

{"icon":"<i class=\"remove_icon\" title=\"Request declined\"><\/i>","response":"decline"}

My Ajax code:

$  ('.accept_decline a').live('click', function(event){
    event.preventDefault();

    var link = $  (this).attr('href');
    var last_seg = link.substr(link.lastIndexOf('/') + 1); //grab segment 4 of link

    $  .ajax({
        url: link,
        dataType: 'json',
        success: function(data) {

            if (data.response === 'accept') {

                $  ('#accept_' + last_seg).html(data.icon);
                $  ('#decline_' + last_seg).remove();
                $  ('.accept_decline').css('width', '35px');

            } else if (data.response === 'decline') {

                $  ('#accept_' + last_seg).remove();
                $  ('#decline_' + last_seg).html(data.icon);
                $  ('.accept_decline').css('width', '35px');
            }
        }
    });
});

HTML

        <td class="search_table_right_col accept_decline" style="width:50px">

            <a href="<?php echo base_url() . 'social/friends/accept/' . $  data->user_id . '/' . $  friends_id; ?>" id="accept_<?php echo $  friends_id; ?>">

                <i class="not_friend_icon" title="Accept request"></i>
            </a>

            <a href="<?php echo base_url() . 'social/friends/decline/' . $  data->user_id . '/' . $  friends_id; ?>" id="decline_<?php echo $  friends_id; ?>">
                <i class="remove_icon" title="Decline request"></i>
            </a>
        </td>

My problem:

When I accept a friend request, everything works fine (ie, all lines of the if... accept run).

But if I decline a request, nothing happens. No error on console. For both situations, the console shows exactly the JSON response strings above. It’s just that decline has no effect.

Placing a console.log or alert within the else if... decline also does not render anything.

What am I doing wrong?

newest questions tagged jquery – Stack Overflow

]]>
https://jqueryplugins.info/2011/10/ajax-not-processing-json-response/feed/ 0
Using $.each for more complex JSON data https://jqueryplugins.info/2011/10/using-each-for-more-complex-json-data/ https://jqueryplugins.info/2011/10/using-each-for-more-complex-json-data/#comments Thu, 13 Oct 2011 10:13:33 +0000 Admin https://jqueryplugins.info/2011/10/using-each-for-more-complex-json-data/ Post link: Using $.each for more complex JSON data

I understand how to use $ .each to go through JSON data which looks like this: { "one": "Singular sensation", "two": "Beady little eyes", "three": "Little birds pitch by my...

]]>
Post link: Using $.each for more complex JSON data

I understand how to use $ .each to go through JSON data which looks like this:

{
  "one": "Singular sensation",
  "two": "Beady little eyes",
  "three": "Little birds pitch by my doorstep"
}

For example:

$  .each(data, function(key, val) {
    echo '<div>' + val + '-' + key + '</div>';
  });

But how do I use $ .each to go though JSON data which looks like this:

{
    "d": [
        {
            "__type": "Tab",
            "id": 1,
            "name": "Innovation",
            "ordering": 0
        },
        {
            "__type": "Tab",
            "id": 3,
            "name": "Thought",
            "ordering": 0
        },
        {
            "__type": "Tab",
            "id": 0,
            "name": "Collaboration",
            "ordering": 0
        }
    ]
}

Where I want to use the id and name.

newest questions tagged jquery – Stack Overflow

]]>
https://jqueryplugins.info/2011/10/using-each-for-more-complex-json-data/feed/ 0
How to parse json response and add functions like error,complete to it using JQuery? https://jqueryplugins.info/2011/10/how-to-parse-json-response-and-add-functions-like-errorcomplete-to-it-using-jquery/ https://jqueryplugins.info/2011/10/how-to-parse-json-response-and-add-functions-like-errorcomplete-to-it-using-jquery/#comments Wed, 12 Oct 2011 11:14:09 +0000 Admin https://jqueryplugins.info/2011/10/how-to-parse-json-response-and-add-functions-like-errorcomplete-to-it-using-jquery/ Post link: How to parse json response and add functions like error,complete to it using JQuery?

I am working on making a mini app using Json parsing . Output I am getting by hitting url http://localhost:3000/cities.json is as below [ { "id": 1, "name": "Bangalore" },...

]]>
Post link: How to parse json response and add functions like error,complete to it using JQuery?

I am working on making a mini app using Json parsing . Output I am getting by hitting url http://localhost:3000/cities.json is as below

[
    {
    "id": 1,
    "name": "Bangalore"
    },
    {
    "id": 2,
    "name": "Chandigarh"
    },
    {
    "id": 3,
    "name": "Chennai"
    },
    {
    "id": 4,
    "name": "Hyderabad"
    },
]

I have parsed this using function

  $  .getJSON("http://localhost:3000/cities.json?&callback=?", function(data) {
                //something something
 }

Now I want to add .error function to it so in case there is some issue with response or say server doesnt respond i may get to know about it say by putting an alert like

.error(function(){alert("error");})

I tried it in following way

  $  .getJSON("http://localhost:3000/cities.json?&callback=?", function(data) {
                //something something
         }).error(function(){
            alert("error");
         })

I tried it using this way as well

     var cities = $  .getJSON("http://localhost:3000/cities.json");
                   cities.error("hi");

But none of them is working. To check for error i stop my local server and it doesnt give me any alert for that . Please guide me which way should i proceed ?

newest questions tagged jquery – Stack Overflow

]]>
https://jqueryplugins.info/2011/10/how-to-parse-json-response-and-add-functions-like-errorcomplete-to-it-using-jquery/feed/ 0
MappingJacksonHttpMessageConverter JSON to Jquery DataTable https://jqueryplugins.info/2011/10/mappingjacksonhttpmessageconverter-json-to-jquery-datatable/ https://jqueryplugins.info/2011/10/mappingjacksonhttpmessageconverter-json-to-jquery-datatable/#comments Wed, 12 Oct 2011 08:15:15 +0000 Admin https://jqueryplugins.info/2011/10/mappingjacksonhttpmessageconverter-json-to-jquery-datatable/ Post link: MappingJacksonHttpMessageConverter JSON to Jquery DataTable

Below is my Spring REST controller which returns json/text/xml data depends on the content-type @RequestMapping(value = "/RequestEmp.htm", headers = "Accept=application/json, text/plain, application/xml") public @ResponseBody Emp fetchEmp() { Employee emp=EmployeeDAO.selectEmp(); System.out.println(emp);...

]]>
Post link: MappingJacksonHttpMessageConverter JSON to Jquery DataTable

Below is my Spring REST controller which returns json/text/xml data depends on the content-type

@RequestMapping(value = "/RequestEmp.htm", headers = "Accept=application/json, text/plain, application/xml")
        public @ResponseBody
        Emp fetchEmp() {

            Employee emp=EmployeeDAO.selectEmp();
            System.out.println(emp);
            return emp;
    }

Below is the Jquery DataTable which calls the above service

oTable =$  ("#myTable").dataTable({
                                        bJQueryUI: true,
                                        "sAjaxSource": dataSource,
                                                                                //"aoColumnDefs": [ { "bSearchable": false, "bVisible": false, "aTargets": [ 1 ] }]
                "aoColumns": [
                                { "sName": "aprop" },
                                { "sName": "bprop" },
                                { "sName": "cprop" },
                                { "sName": "dprop" },
                                { "sName": "eprop" },
                                { "sName": "fprop" },
                                { "sName": "gprop" },
                                { "sName": "hprop" },
                                { "sName": "iprop" },
                                { "sName": "jprop" },
                                { "sName": "kprop" },
                                { "sName": "lprop" }
                                ] 

                            });

Not populating the JSON value. What whould be gone wrong?

newest questions tagged jquery – Stack Overflow

]]>
https://jqueryplugins.info/2011/10/mappingjacksonhttpmessageconverter-json-to-jquery-datatable/feed/ 0