[jQuery] Re: ajax request with datatype:script
the second parameter is success, still need to eval(data) to create those vars On Sep 23, 11:23 am, david [EMAIL PROTECTED] wrote: the success function takes a second parameter, the status of the response evaluation. Can you please check it ? On Sep 23, 2:08 am, seo++ [EMAIL PROTECTED] wrote: I am not getting an array, I am getting ids.js contents On Sep 22, 8:12 pm, FrenchiINLA [EMAIL PROTECTED] wrote: inside of your success function success: function(data){} you should refer to 'data' if you're getting back an array, you can refer to as data[0][0] On Sep 21, 9:04 pm, seo++ [EMAIL PROTECTED] wrote: I am trying to insert array elements through ajax request, these elements are also arrays or multidimensional arrays. here is an example main script : var list = []; $.ajax({ type: POST, url: 'http://example.com/ids.js', data: id=1 , dataType: script, success: function(data){ alert( list[1][0] ); } }); ids.js contents: list[1] = [['aaa', 'bbb'], ['ccc', 'ddd']]; that would produce ' list is undefined' error but changing datatype to 'html' and adding eval() would work fine var list = []; $.ajax({ type: POST, url: 'http://example.com/ids.js', data: id=1 , dataType: html, success: function(data){ eval( data); alert( list[1][0] ); } }); any ideas what am i doing wrong ?
[jQuery] ajax request with datatype:script
I am trying to insert array elements through ajax request, these elements are also arrays or multidimensional arrays. here is an example main script : var list = []; $.ajax({ type: POST, url: 'http://example.com/ids.js', data: id=1 , dataType: script, success: function(data){ alert( list[1][0] ); } }); ids.js contents: list[1] = [['aaa', 'bbb'], ['ccc', 'ddd']]; that would produce ' list is undefined' error but changing datatype to 'html' and adding eval() would work fine var list = []; $.ajax({ type: POST, url: 'http://example.com/ids.js', data: id=1 , dataType: html, success: function(data){ eval( data); alert( list[1][0] ); } }); any ideas what am i doing wrong ?
[jQuery] Re: ajax request with datatype:script
server side sends ids.js mentioned in first post it's a JavaScript array On Sep 22, 2:33 pm, david [EMAIL PROTECTED] wrote: Hi, What do you get from the server side ? I think you are getting a json structure. But this is text for javascript till you make eval; instead of theajaxfunction try getjson. Best regards, David On Sep 22, 7:04 am, seo++ [EMAIL PROTECTED] wrote: I am trying to insert array elements throughajaxrequest, these elements are also arrays or multidimensional arrays. here is an example main script : var list = []; $.ajax({ type: POST, url: 'http://example.com/ids.js', data: id=1 , dataType: script, success: function(data){ alert( list[1][0] ); } }); ids.js contents: list[1] = [['aaa', 'bbb'], ['ccc', 'ddd']]; that would produce ' list is undefined' error but changingdatatypeto 'html' and adding eval() would work fine var list = []; $.ajax({ type: POST, url: 'http://example.com/ids.js', data: id=1 , dataType: html, success: function(data){ eval( data); alert( list[1][0] ); } }); any ideas what am i doing wrong ?
[jQuery] Re: ajax request with datatype:script
the server side sends ids.js it's a JavaScript Array On Sep 22, 2:33 pm, david [EMAIL PROTECTED] wrote: Hi, What do you get from the server side ? I think you are getting a json structure. But this is text for javascript till you make eval; instead of the ajax function try getjson. Best regards, David On Sep 22, 7:04 am, seo++ [EMAIL PROTECTED] wrote: I am trying to insert array elements through ajax request, these elements are also arrays or multidimensional arrays. here is an example main script : var list = []; $.ajax({ type: POST, url: 'http://example.com/ids.js', data: id=1 , dataType: script, success: function(data){ alert( list[1][0] ); } }); ids.js contents: list[1] = [['aaa', 'bbb'], ['ccc', 'ddd']]; that would produce ' list is undefined' error but changing datatype to 'html' and adding eval() would work fine var list = []; $.ajax({ type: POST, url: 'http://example.com/ids.js', data: id=1 , dataType: html, success: function(data){ eval( data); alert( list[1][0] ); } }); any ideas what am i doing wrong ?
[jQuery] Re: ajax request with datatype:script
I am not getting an array, I am getting ids.js contents On Sep 22, 8:12 pm, FrenchiINLA [EMAIL PROTECTED] wrote: inside of your success function success: function(data){} you should refer to 'data' if you're getting back an array, you can refer to as data[0][0] On Sep 21, 9:04 pm, seo++ [EMAIL PROTECTED] wrote: I am trying to insert array elements through ajax request, these elements are also arrays or multidimensional arrays. here is an example main script : var list = []; $.ajax({ type: POST, url: 'http://example.com/ids.js', data: id=1 , dataType: script, success: function(data){ alert( list[1][0] ); } }); ids.js contents: list[1] = [['aaa', 'bbb'], ['ccc', 'ddd']]; that would produce ' list is undefined' error but changing datatype to 'html' and adding eval() would work fine var list = []; $.ajax({ type: POST, url: 'http://example.com/ids.js', data: id=1 , dataType: html, success: function(data){ eval( data); alert( list[1][0] ); } }); any ideas what am i doing wrong ?
[jQuery] Re: selectors
that worked! thanks again! On Sep 5, 10:53 am, Michael Geary [EMAIL PROTECTED] wrote: if I need the Dom node and jQuery object on the same function should I give each different variables or is there a workaround ? Given a jQuery object, you can always get directly to its DOM node(s) with [0], [1], etc. So you don't *need* another variable, but you can always use one if you want. I do this quite often, when I'm using a jQuery selector that I know will return only a single DOM node, e.g. an ID selector like this: var $foo = $('#foo'), foo = $foo[0]; // $foo is a jQuery object, foo is the matching DOM node. // These should alert the same value: alert( $foo.html() ); alert( foo.innerHTML ); I also do this the other way around when I have a DOM node to start with. Suppose I have a function that takes a DOM node as an argument: function test( element ) { var $element = $(element); // $element is the jQuery object // element is the DOM node } In both cases I use the convention of $xyz for the jQuery object and just plain xyz for the corresponding DOM object. This lets me see when reading the code that they are closely tied together, while still making it easy to tell them apart. -Mike
[jQuery] Re: selectors
Thank you Mike. if I need the Dom node and jQuery object on the same function should I give each different variables or is there a workaround ? On Sep 3, 6:35 am, Michael Geary [EMAIL PROTECTED] wrote: Imagine that you have an array: var a = [ 'a', 'b', 'c' ]; Now you can call array methods on the array: var t = a.join(); // 'a,b,c' But what happens if you call an array method on one of the *elements* of the array? var x = a[0].join(); That's an error, because a[0] is a *string*, not an array. In the same way, $(whatever) returns a jQuery object, with jQuery methods such as .val(), .css(), etc. The jQuery object is also an array-like object, so you can retrieve the array elements with [0], [1], etc. But those array elements are *DOM nodes*, not jQuery objects themselves. So, $(whatever)[0] gives you a DOM node, with properties like defaultValue, but this DOM node does not have the jQuery methods, because it's not a jQuery object. -Mike for this form form name=f1 method=get action=/search id=searchform input type=text name=q value=Search size=70 / input type=submit value=Search / /form why $(#searchform input)[0] is different than $(#searchform input:first) I can get values for $(#searchform input)[0].defaultValue or .value but not with .fadeIn() or val() while the reverse for the $ (#searchform input:first)
[jQuery] selectors
for this form form name=f1 method=get action=/search id=searchform input type=text name=q value=Search size=70 / input type=submit value=Search / /form why $(#searchform input)[0] is different than $(#searchform input:first) I can get values for $(#searchform input)[0].defaultValue or .value but not with .fadeIn() or val() while the reverse for the $ (#searchform input:first)