[Moo] json request choose one and scroll to next

10 messages Options
Embed this post
Permalink
hamburger

[Moo] json request choose one and scroll to next

Reply Threaded More More options
Print post
Permalink

Hello, I have the following code witch works fine. But I'am a newbe
and dont get what i want.
I would like to display one line out of the jason request choosen
randomly.
After that i would like to have a button to scroll to the next line.
Somebody can help??

Thanx in advance.


        var path = 'http://api.kivaws.org/v1/';
        var writehere = $('hierhin');

    var request = new Request.JSON({
                        url: path + 'lending_actions/recent.json',
                        onComplete: function(jsonObj) {
                //var rand = $random(0,
jsonObj.lending_actions.length-1);
                                //addText(jsonObj.lending_actions[rand]);
                           addText(jsonObj.lending_actions);
                        }
                }).send();

        var addText = function(addArchiv) {

        zufall =$random(0,99);
        var name = new Element('h2', {'html': 'Hallo'});

                addArchiv.each(function(item, index) {
        //if(index==zufall)
        {
          var liste = new Element('ul', {'class': 'recentlist'}).inject
(name);
        var el = new Element('li', {'html': 'index:'+index+' item:
'+item.id+' <a href="'+item.date+'"
class="loadMe">'+item.loan.use}).inject(liste);
        }
                });

        name.inject(writehere); // Einfügen bei id=hierhin

        };


});
hamburger

[Moo] Re: json request choose one and scroll to next

Reply Threaded More More options
Print post
Permalink

I have a little more now. Here my advanced code.
The problem is, that it will loose the array whwnn i call muller
(new_item);
any solution here ?????





window.addEvent('domready', function() {

        var path = 'http://api.kivaws.org/v1/';
        var writehere = $('hierhin');
    var rand = 0;
    var arrayLaenge = 0;

    var request = new Request.JSON({
                        url: path + 'lending_actions/recent.json',
                        onComplete: function(jsonObj) {
                rand = $random(0, jsonObj.lending_actions.length-1);
                arrayLaenge = jsonObj.lending_actions.length-1;
                                addText(jsonObj.lending_actions[rand]);
                        }
                }).send();

        var addText = function muller(item) {

var archiveHTML="<h3>Archive text von joe</h3>";
archiveHTML+="<div class=\"single\" id=\""+item.id+"\">";
archiveHTML+="<div class=\"post\"><div class=\"day\">"+item.date+"</
div>";
archiveHTML+="<div class=\"month\">"+item.loan.use+"</div>";
archiveHTML+="</div><h4>"+item.id+" <span class=\"author\"> by "+rand
+"</span></h4>";
archiveHTML+="<p>"+item.id+"</p></div>";

        writehere.set('html', archiveHTML); //löscht vorhandenes  und
trägt neues ein.
        };

    // Add Button to Change ArrayItem
    $('more_changer').addEvent('click', function() {setStateForItem
(0);});


function setStateForItem(item)

{new_item = rand + 1;
if(new_item =(arrayLaenge+1)){new_item=0;};
alert(rand);
muller(new_item);
};


});
On 30 Okt., 12:44, hamburger <[hidden email]> wrote:

> Hello, I have the following code witch works fine. But I'am a newbe
> and dont get what i want.
> I would like to display one line out of the jason request choosen
> randomly.
> After that i would like to have a button to scroll to the next line.
> Somebody can help??
>
> Thanx in advance.
>
>         var path = 'http://api.kivaws.org/v1/';
>         var writehere = $('hierhin');
>
>     var request = new Request.JSON({
>                         url: path + 'lending_actions/recent.json',
>                         onComplete: function(jsonObj) {
>                 //var rand = $random(0,
> jsonObj.lending_actions.length-1);
>                                 //addText(jsonObj.lending_actions[rand]);
>                            addText(jsonObj.lending_actions);
>                         }
>                 }).send();
>
>         var addText = function(addArchiv) {
>
>         zufall =$random(0,99);
>         var name = new Element('h2', {'html': 'Hallo'});
>
>                 addArchiv.each(function(item, index) {
>         //if(index==zufall)
>         {
>                 var liste = new Element('ul', {'class': 'recentlist'}).inject
> (name);
>         var el = new Element('li', {'html': 'index:'+index+' item:
> '+item.id+' <a href="'+item.date+'"
> class="loadMe">'+item.loan.use}).inject(liste);
>         }
>                 });
>
>         name.inject(writehere); // Einfügen bei id=hierhin
>
>         };
>
>
>
> });- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -
Oskar Krawczyk

[Moo] Re: json request choose one and scroll to next

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
Put your code within a mooshell (http://mooshell.net)– I doubt anyone here has the time to dry-try the code.

On 30 Oct 2009, at 18:52, hamburger wrote:


I have a little more now. Here my advanced code.
The problem is, that it will loose the array whwnn i call muller
(new_item);
any solution here ?????





window.addEvent('domready', function() {

var path = 'http://api.kivaws.org/v1/';
var writehere = $('hierhin');
   var rand = 0;
   var arrayLaenge = 0;

   var request = new Request.JSON({
url: path + 'lending_actions/recent.json',
onComplete: function(jsonObj) {
               rand = $random(0, jsonObj.lending_actions.length-1);
               arrayLaenge = jsonObj.lending_actions.length-1;
addText(jsonObj.lending_actions[rand]);
}
}).send();

var addText = function muller(item) {

var archiveHTML="<h3>Archive text von joe</h3>";
archiveHTML+="<div class=\"single\" id=\""+item.id+"\">";
archiveHTML+="<div class=\"post\"><div class=\"day\">"+item.date+"</
div>";
archiveHTML+="<div class=\"month\">"+item.loan.use+"</div>";
archiveHTML+="</div><h4>"+item.id+" <span class=\"author\"> by "+rand
+"</span></h4>";
archiveHTML+="<p>"+item.id+"</p></div>";

       writehere.set('html', archiveHTML); //löscht vorhandenes  und
trägt neues ein.
};

   // Add Button to Change ArrayItem
   $('more_changer').addEvent('click', function() {setStateForItem
(0);});


function setStateForItem(item)

{new_item = rand + 1;
if(new_item =(arrayLaenge+1)){new_item=0;};
alert(rand);
muller(new_item);
};


});
On 30 Okt., 12:44, hamburger <[hidden email]> wrote:
Hello, I have the following code witch works fine. But I'am a newbe
and dont get what i want.
I would like to display one line out of the jason request choosen
randomly.
After that i would like to have a button to scroll to the next line.
Somebody can help??

Thanx in advance.

        var path = 'http://api.kivaws.org/v1/';
        var writehere = $('hierhin');

    var request = new Request.JSON({
                        url: path + 'lending_actions/recent.json',
                        onComplete: function(jsonObj) {
                //var rand = $random(0,
jsonObj.lending_actions.length-1);
                                //addText(jsonObj.lending_actions[rand]);
                           addText(jsonObj.lending_actions);
                        }
                }).send();

        var addText = function(addArchiv) {

        zufall =$random(0,99);
        var name = new Element('h2', {'html': 'Hallo'});

                addArchiv.each(function(item, index) {
        //if(index==zufall)
        {
                var liste = new Element('ul', {'class': 'recentlist'}).inject
(name);
        var el = new Element('li', {'html': 'index:'+index+' item:
'+item.id+'&nbsp;<a href="'+item.date+'"
class="loadMe">'+item.loan.use}).inject(liste);
        }
                });

        name.inject(writehere); // Einfügen bei id=hierhin

        };



});- Zitierten Text ausblenden -

- Zitierten Text anzeigen -

hamburger

[Moo] Re: json request choose one and scroll to next

Reply Threaded More More options
Print post
Permalink
In reply to this post by hamburger

here it is

http://mooshell.net/uzxhV/

but i get an access error i dont have it with my browser


On 30 Okt., 19:52, hamburger <[hidden email]> wrote:

> I have a little more now. Here my advanced code.
> The problem is, that it will loose the array whwnn i call muller
> (new_item);
> any solution here ?????
>
> window.addEvent('domready', function() {
>
>         var path = 'http://api.kivaws.org/v1/';
>         var writehere = $('hierhin');
>     var rand = 0;
>     var arrayLaenge = 0;
>
>     var request = new Request.JSON({
>                         url: path + 'lending_actions/recent.json',
>                         onComplete: function(jsonObj) {
>                 rand = $random(0, jsonObj.lending_actions.length-1);
>                 arrayLaenge = jsonObj.lending_actions.length-1;
>                                 addText(jsonObj.lending_actions[rand]);
>                         }
>                 }).send();
>
>         var addText = function muller(item) {
>
> var archiveHTML="<h3>Archive text von joe</h3>";
> archiveHTML+="<div class=\"single\" id=\""+item.id+"\">";
> archiveHTML+="<div class=\"post\"><div class=\"day\">"+item.date+"</
> div>";
> archiveHTML+="<div class=\"month\">"+item.loan.use+"</div>";
> archiveHTML+="</div><h4>"+item.id+" <span class=\"author\"> by "+rand
> +"</span></h4>";
> archiveHTML+="<p>"+item.id+"</p></div>";
>
>         writehere.set('html', archiveHTML); //löscht vorhandenes  und
> trägt neues ein.
>         };
>
>     // Add Button to Change ArrayItem
>     $('more_changer').addEvent('click', function() {setStateForItem
> (0);});
>
> function setStateForItem(item)
>
> {new_item = rand + 1;
> if(new_item =(arrayLaenge+1)){new_item=0;};
> alert(rand);
> muller(new_item);
>
> };
> });
>
> On 30 Okt., 12:44, hamburger <[hidden email]> wrote:
>
>
>
> > Hello, I have the following code witch works fine. But I'am a newbe
> > and dont get what i want.
> > I would like to display one line out of the jason request choosen
> > randomly.
> > After that i would like to have a button to scroll to the next line.
> > Somebody can help??
>
> > Thanx in advance.
>
> >         var path = 'http://api.kivaws.org/v1/';
> >         var writehere = $('hierhin');
>
> >     var request = new Request.JSON({
> >                         url: path + 'lending_actions/recent.json',
> >                         onComplete: function(jsonObj) {
> >                 //var rand = $random(0,
> > jsonObj.lending_actions.length-1);
> >                                 //addText(jsonObj.lending_actions[rand]);
> >                            addText(jsonObj.lending_actions);
> >                         }
> >                 }).send();
>
> >         var addText = function(addArchiv) {
>
> >         zufall =$random(0,99);
> >         var name = new Element('h2', {'html': 'Hallo'});
>
> >                 addArchiv.each(function(item, index) {
> >         //if(index==zufall)
> >         {
> >                 var liste = new Element('ul', {'class': 'recentlist'}).inject
> > (name);
> >         var el = new Element('li', {'html': 'index:'+index+' item:
> > '+item.id+' <a href="'+item.date+'"
> > class="loadMe">'+item.loan.use}).inject(liste);
> >         }
> >                 });
>
> >         name.inject(writehere); // Einfügen bei id=hierhin
>
> >         };
>
> > });- Zitierten Text ausblenden -
>
> > - Zitierten Text anzeigen -- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -
Sanford Whiteman [Mobile]

[Moo] Re: json request choose one and scroll to next

Reply Threaded More More options
Print post
Permalink

> but i get an access error i dont have it with my browser

B/c of the same-origin security policy.

Use  Mooshell's built-in 'JSON echo' feature to simulate XHR response.
There is a demo on the site.

-- Sandy

hamburger

[Moo] Re: json request choose one and scroll to next

Reply Threaded More More options
Print post
Permalink

Hello, I think i do not have a jason problem.
I'am would like to read the hole file witch is provided by kiva.org
this part works!
I'am a newbe and have problems with the syntax and sometimes with the
object-oriented-stuff.

do i find the Mooshell's built-in 'JSON echo' here: http://mooshell.net/json/
???
I have the same error here.
thx for your fast answer


On 30 Okt., 20:27, Sanford Whiteman <[hidden email]>
wrote:
> > but i get an access error i dont have it with my browser
>
> B/c of the same-origin security policy.
>
> Use  Mooshell's built-in 'JSON echo' feature to simulate XHR response.
> There is a demo on the site.
>
> -- Sandy
hamburger

[Moo] Re: json request choose one and scroll to next

Reply Threaded More More options
Print post
Permalink

hello,
everything with jason works fine now.
only the function setStateForItem(item) to scroll to next gives the
error:undefined.
can somebody have a quick look?
thx

On 30 Okt., 20:45, hamburger <[hidden email]> wrote:

> Hello, I think i do not have a jason problem.
> I'am would like to read the hole file witch is provided by kiva.org
> this part works!
> I'am a newbe and have problems with the syntax and sometimes with the
> object-oriented-stuff.
>
> do i find the Mooshell's built-in 'JSON echo' here:http://mooshell.net/json/
> ???
> I have the same error here.
> thx for your fast answer
>
> On 30 Okt., 20:27, Sanford Whiteman <[hidden email]>
> wrote:
>
>
>
> > > but i get an access error i dont have it with my browser
>
> > B/c of the same-origin security policy.
>
> > Use  Mooshell's built-in 'JSON echo' feature to simulate XHR response.
> > There is a demo on the site.
>
> > -- Sandy- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -
cronix-2

[Moo] Re: json request choose one and scroll to next

Reply Threaded More More options
Print post
Permalink

function setStateForItem(item)
{
new_item = rand +1;
if(new_item >(arrayLaenge)){new_item=0;};
muller(new_item);
};

This function does not know what 'arrayLaenge' is because its not
defined within or passed to the function.  You also never use 'item'
in the function.  'rand' is not defined either.  If those are defined
elsewhere you need to pass them to the function as well.  Basically,
you have a scope problem.

On Oct 30, 1:30 pm, hamburger <[hidden email]> wrote:

> hello,
> everything with jason works fine now.
> only the function setStateForItem(item) to scroll to next gives the
> error:undefined.
> can somebody have a quick look?
> thx
>
> On 30 Okt., 20:45, hamburger <[hidden email]> wrote:
>
> > Hello, I think i do not have a jason problem.
> > I'am would like to read the hole file witch is provided by kiva.org
> > this part works!
> > I'am a newbe and have problems with the syntax and sometimes with the
> > object-oriented-stuff.
>
> > do i find the Mooshell's built-in 'JSON echo' here:http://mooshell.net/json/
> > ???
> > I have the same error here.
> > thx for your fast answer
>
> > On 30 Okt., 20:27, Sanford Whiteman <[hidden email]>
> > wrote:
>
> > > > but i get an access error i dont have it with my browser
>
> > > B/c of the same-origin security policy.
>
> > > Use  Mooshell's built-in 'JSON echo' feature to simulate XHR response.
> > > There is a demo on the site.
>
> > > -- Sandy- Zitierten Text ausblenden -
>
> > - Zitierten Text anzeigen -
hamburger

[Moo] Re: json request choose one and scroll to next

Reply Threaded More More options
Print post
Permalink

Thx CroNiX for your answer.
arrayLaenge and rand is defined. (as you see in my second post)
The test alert(rand) shows OK.
But Indeed the problem is how to give the new array[index] to  addText
= function muller(item).
Thats what I dont know how.
Normally I do that like his: states.blah[index].date
I dont get to do it with this json stuff. (here I dont understand the
"item" either)
any further help?



On 30 Okt., 22:35, CroNiX <[hidden email]> wrote:

> function setStateForItem(item)
> {
> new_item = rand +1;
> if(new_item >(arrayLaenge)){new_item=0;};
> muller(new_item);
>
> };
>
> This function does not know what 'arrayLaenge' is because its not
> defined within or passed to the function.  You also never use 'item'
> in the function.  'rand' is not defined either.  If those are defined
> elsewhere you need to pass them to the function as well.  Basically,
> you have a scope problem.
>
> On Oct 30, 1:30 pm, hamburger <[hidden email]> wrote:
>
>
>
> > hello,
> > everything with jason works fine now.
> > only the function setStateForItem(item) to scroll to next gives the
> > error:undefined.
> > can somebody have a quick look?
> > thx
>
> > On 30 Okt., 20:45, hamburger <[hidden email]> wrote:
>
> > > Hello, I think i do not have a jason problem.
> > > I'am would like to read the hole file witch is provided by kiva.org
> > > this part works!
> > > I'am a newbe and have problems with the syntax and sometimes with the
> > > object-oriented-stuff.
>
> > > do i find the Mooshell's built-in 'JSON echo' here:http://mooshell.net/json/
> > > ???
> > > I have the same error here.
> > > thx for your fast answer
>
> > > On 30 Okt., 20:27, Sanford Whiteman <[hidden email]>
> > > wrote:
>
> > > > > but i get an access error i dont have it with my browser
>
> > > > B/c of the same-origin security policy.
>
> > > > Use  Mooshell's built-in 'JSON echo' feature to simulate XHR response.
> > > > There is a demo on the site.
>
> > > > -- Sandy- Zitierten Text ausblenden -
>
> > > - Zitierten Text anzeigen -- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -
hamburger

[Moo] Re: json request choose one and scroll to next

Reply Threaded More More options
Print post
Permalink

Live is hard when you are alone ... but in the end its easier.
here is my working code now.
may be there is somebody here in this group who need it or wants to
make suggestions for improvements


window.addEvent('domready', function()
{

    function muller(item)
    {
        //item
        var archiveHTML="<h3>Archive text von joe</h3>";
        archiveHTML+="<div class=\"single\" id=\""+item.id+"\">";
        archiveHTML+="<div class=\"post\"><div class=\"day
\">"+item.loan.name+" / "+item.id+"</div>";
        archiveHTML+="<div class=\"month\">"+item.loan.activity+ " / "
+item.loan.use+ " / " +item.loan.loan_amount+" /
"+item.loan.funded_amount+"</div>";
        archiveHTML+="</div><h4>"+item.loan.image.id+" <span class=
\"author\"> ImageID und zufallsnummer "+currentIndex+"</span></h4>";
        archiveHTML+="</div><img src=\"http://www.kiva.org/img/
w200h200/"+item.loan.image.id+".jpg\">";
        archiveHTML+="<p>"+item.loan.location.country+ " / "
+item.loan.location.town+ "</p></div>";
        writehere.set('html', archiveHTML); //löscht vorhandenes  und
trägt neues ein.
    };




function nextItem()
{
  currentIndex++;
  if(currentIndex > arrayLaenge){currentIndex = 0;}
  muller(JSONResponse.lending_actions[currentIndex]);
};

function prevItem()
{
  currentIndex--;
  if(currentIndex < 0){currentIndex = arrayLaenge;}
  muller(JSONResponse.lending_actions[currentIndex]);
};

var path = 'http://api.kivaws.org/v1/';
var writehere = $('writehere');
var arrayLaenge = 0;


var JSONResponse = {};
var currentIndex = 0;

var request = new Request.JSON(
{
  url: path + 'lending_actions/recent.json',
  onComplete: function(jsonObj)  {
    currentIndex = $random(0, jsonObj.lending_actions.length-1);
    arrayLaenge = jsonObj.lending_actions.length-1;
    muller(jsonObj.lending_actions[currentIndex]);
    //we assign JSONResponse to the response of the request
    JSONResponse = jsonObj;
  }
}).send();

    $('more_changer').addEvent('click', function() {nextItem();});
    $('prev_changer').addEvent('click', function() {prevItem();});
    //console.log(JSONResponse);

});

On 31 Okt., 11:50, hamburger <[hidden email]> wrote:

> Thx CroNiX for your answer.
> arrayLaenge and rand is defined. (as you see in my second post)
> The test alert(rand) shows OK.
> But Indeed the problem is how to give the new array[index] to  addText
> = function muller(item).
> Thats what I dont know how.
> Normally I do that like his: states.blah[index].date
> I dont get to do it with this json stuff. (here I dont understand the
> "item" either)
> any further help?
>
> On 30 Okt., 22:35, CroNiX <[hidden email]> wrote:
>
>
>
> > function setStateForItem(item)
> > {
> > new_item = rand +1;
> > if(new_item >(arrayLaenge)){new_item=0;};
> > muller(new_item);
>
> > };
>
> > This function does not know what 'arrayLaenge' is because its not
> > defined within or passed to the function.  You also never use 'item'
> > in the function.  'rand' is not defined either.  If those are defined
> > elsewhere you need to pass them to the function as well.  Basically,
> > you have a scope problem.
>
> > On Oct 30, 1:30 pm, hamburger <[hidden email]> wrote:
>
> > > hello,
> > > everything with jason works fine now.
> > > only the function setStateForItem(item) to scroll to next gives the
> > > error:undefined.
> > > can somebody have a quick look?
> > > thx
>
> > > On 30 Okt., 20:45, hamburger <[hidden email]> wrote:
>
> > > > Hello, I think i do not have a jason problem.
> > > > I'am would like to read the hole file witch is provided by kiva.org
> > > > this part works!
> > > > I'am a newbe and have problems with the syntax and sometimes with the
> > > > object-oriented-stuff.
>
> > > > do i find the Mooshell's built-in 'JSON echo' here:http://mooshell.net/json/
> > > > ???
> > > > I have the same error here.
> > > > thx for your fast answer
>
> > > > On 30 Okt., 20:27, Sanford Whiteman <[hidden email]>
> > > > wrote:
>
> > > > > > but i get an access error i dont have it with my browser
>
> > > > > B/c of the same-origin security policy.
>
> > > > > Use  Mooshell's built-in 'JSON echo' feature to simulate XHR response.
> > > > > There is a demo on the site.
>
> > > > > -- Sandy- Zitierten Text ausblenden -
>
> > > > - Zitierten Text anzeigen -- Zitierten Text ausblenden -
>
> > - Zitierten Text anzeigen -- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -