Re: [jQuery] load(),get(),post() params issue

2006-10-20 Thread Klaus Hartl


Miel Soeterbroek schrieb:
> Thanks Blair, changing Array to Object did the trick…
> 
> And indeed, the : was just a typo…
> 
>  
> 
> David, I use the extend functionality all over the place already, 
> however, in this case there is no default set of values. Unset 
> parameters will just arrive as null on the server.
> 
>1. var params = new Array():
>   Probably a typo, but I thought I'd mention it.
>2. Possibly {} creates an object not an array? In which case change
>   var params = new Array();
>   to
>   var params = new Object();


Always remember: Use [] for true index based arrays, use {} for hash maps.

The following is considered bad-practice:

var arr = [];
arr['foo'] = 'bar';

There even was an "JavaScript 'Array' and 'Object.prototype' Awareness 
Day" :-)
http://blog.metawrap.com/blog/June6thIsJavaScriptArrayAndObjectprototypeAwarenessDay.aspx

And:
http://www.andrewdupont.net/2006/05/18/javascript-associative-arrays-considered-harmful/


-- Klaus




___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] load(),get(),post() params issue

2006-10-20 Thread Miel Soeterbroek








Thanks Blair, changing Array to
Object did the trick…

And indeed, the : was
just a typo…

 

David, I use the extend
functionality all over the place already, however, in this case there is no
default set of values. Unset parameters will just arrive as null on the server.


 var params = new
 Array():
 Probably a typo, but I thought I'd mention it. 
 Possibly
 {} creates an object not an array? In which case change
 var params = new Array();
 to
 var params = new Object(); 
 
 


 






___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] load(),get(),post() params issue

2006-10-20 Thread David Duymelinck
Miel Soeterbroek schreef:
>
> Howdy!
>
> Consider the following two pieces of code:
>
> function someFunction() {
>
> var params = {
>
> name: ‘John’,
>
> surname: ‘Doe’
>
> };
>
> $.post(‘save.html’, params, function(data) {
>
> alert(data);
>
> });
>
> }
>
> This works just fine…
>
> The following piece of code doesn’t:
>
> function someFunction() {
>
> var params = new Array():
>
> params[‘name’] = ‘John’;
>
> params[‘surname’] = ‘Doe’;
>
> $.post(‘save.html’, params, function(data) {
>
> alert(data);
>
> });
>
> }
>
>
>   
The common way to do this with jquery plugins is

function(options) {
>   var settings = jQuery.extend({
> name: 'John',
> surname: 'Doe'
>   }, options || {});
>  $.post(‘save.html’,settings, function(data){ alert(data);});

> };




-- 
David Duymelinck

[EMAIL PROTECTED]


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] load(),get(),post() params issue

2006-10-20 Thread Blair McKenzie
var params = new
Array():Probably a typo, but I thought I'd mention it.
Possibly {} creates an object not an array? In which case changevar params = new
Array();tovar params = new Object();
BlairOn 10/20/06, Miel Soeterbroek
 <[EMAIL PROTECTED]> wrote:














Howdy!

 

Consider the following two pieces of code:

 

    function someFunction() {

    var params =
{ 

name: 'John',


surname: 'Doe'


};

    $.post('save.html',
params, function(data) {

        alert(data);

});

}

 

This works just fine…

The following piece of code doesn't:

 

function someFunction() {

    var params = new
Array():

    params['name']
= 'John';

    params['surname']
= 'Doe';

$.post('save.html',
params, function(data) {

        alert(data);

});

}

 

Am I just missing some _javascript_ array basics (which
is totally possible) or is there something weird going on here.

Since I need to post a variable number of variables,
with variable names as well, i need something like the second example.

 

Thanks,
Miel



 







___jQuery mailing listdiscuss@jquery.com
http://jquery.com/discuss/
___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


[jQuery] load(),get(),post() params issue

2006-10-20 Thread Miel Soeterbroek










Howdy!

 

Consider the following two pieces of code:

 

    function someFunction() {

    var params =
{ 

name: ‘John’,


surname: ‘Doe’


};

    $.post(‘save.html’,
params, function(data) {

        alert(data);

});

}

 

This works just fine…

The following piece of code doesn’t:

 

function someFunction() {

    var params = new
Array():

    params[‘name’]
= ‘John’;

    params[‘surname’]
= ‘Doe’;

$.post(‘save.html’,
params, function(data) {

        alert(data);

});

}

 

Am I just missing some _javascript_ array basics (which
is totally possible) or is there something weird going on here.

Since I need to post a variable number of variables,
with variable names as well, i need something like the second example.

 

Thanks,
Miel



 






___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/