dgrafx
asked on
syntax and how to help
Part 1
We have a js function that loads a colorbox sending an object (qstr) with the url to the href setting
heres a simple ex:
qstr={abc:105487,xyz:18199 };
href: '/testing.cfm?qstr=' + qstr
Part 2
now on testing.cfm from the above if i dump url.qstr it says it's [object Object] but cant figure out how to parse through it.
when trying to use $.each i get the "cannot use 'in' operator to search for ..." error
insight is needed ...
We have a js function that loads a colorbox sending an object (qstr) with the url to the href setting
heres a simple ex:
qstr={abc:105487,xyz:18199
href: '/testing.cfm?qstr=' + qstr
Part 2
now on testing.cfm from the above if i dump url.qstr it says it's [object Object] but cant figure out how to parse through it.
when trying to use $.each i get the "cannot use 'in' operator to search for ..." error
insight is needed ...
ASKER
hi Rob - there really isn't any CF code which is why I didn't include the CF zone
the only CF is where I turn url.qstr back into a js object
qstr = '#url.qstr#';
insight?
the only CF is where I turn url.qstr back into a js object
qstr = '#url.qstr#';
insight?
Have you tried console.dir(your object)?
If you could site the $.each code you used, that would help.
Was it just
$.each(qstr, function(i,el) {
console.dir(el);
});
Was it just
$.each(qstr, function(i,el) {
console.dir(el);
});
ASKER
yes i used similar
$.each(qstr, function(i,el) {
console.log(el);
});
i also used console.log(qstr) which equals [object Object] but no option to expand to see it's contents so am wondering if it really is an object?
i don't need to do this exactly like I've shown so if you have a better method of sending the original object - which will be something like {abc:105487,xyz:18199} - through the url and parsing through it on the landing page.
I'm leaving right now for work and can post more when I get there so forgive the delay if you post back ...
$.each(qstr, function(i,el) {
console.log(el);
});
i also used console.log(qstr) which equals [object Object] but no option to expand to see it's contents so am wondering if it really is an object?
i don't need to do this exactly like I've shown so if you have a better method of sending the original object - which will be something like {abc:105487,xyz:18199} - through the url and parsing through it on the landing page.
I'm leaving right now for work and can post more when I get there so forgive the delay if you post back ...
> qstr = '#url.qstr#';
@dgrafx - Quick thought. I don't think it is an object (from javascript's POV). Due to the surrounding quotes, it looks like it's assigning a simple string. That's why an error occurs when trying to loop through it.
ie
@dgrafx - Quick thought. I don't think it is an object (from javascript's POV). Due to the surrounding quotes, it looks like it's assigning a simple string. That's why an error occurs when trying to loop through it.
ie
// assigns string
var qstr = '{abc:105487,xyz:18199}';
// assigns object
var qstr = {abc:105487,xyz:18199};
ASKER
right!
this is the thing
for testing if i code exactly this on the landing page:
var qstr = {abc:105487,xyz:18199};
$.each(qstr, function(i,el) {
console.log(el);
});
then no problem - good to go
But what I need to do is send this "object" in the url to the landing page
Thus the issue as to what to do with #url.qstr#
i.e. how to loop through it just as if it was created like var qstr = {abc:105487,xyz:18199};
thanks
this is the thing
for testing if i code exactly this on the landing page:
var qstr = {abc:105487,xyz:18199};
$.each(qstr, function(i,el) {
console.log(el);
});
then no problem - good to go
But what I need to do is send this "object" in the url to the landing page
Thus the issue as to what to do with #url.qstr#
i.e. how to loop through it just as if it was created like var qstr = {abc:105487,xyz:18199};
thanks
Can you change the format of URL.qstr, so it's valid JSON? Then run it through JSON.parse, and voila its' an object.
Other than that, the only thing I'm coming up with is to eval() the string, but ... that's not a great idea at all.
Other than that, the only thing I'm coming up with is to eval() the string, but ... that's not a great idea at all.
ASKER
can you post an example?
and yes I can change the format
one of the first things i did was to try and send in valid json as in: {"abc":"10587","xyz":"1819 9"}
but still seems to convert to a string on landing page when translated i.e. #url.qstr#
thanks
and yes I can change the format
one of the first things i did was to try and send in valid json as in: {"abc":"10587","xyz":"1819
but still seems to convert to a string on landing page when translated i.e. #url.qstr#
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think it'll work using a plain output:
var qStr = '#url.qStr#';
... instead of this:
<cfoutput>
#toScript(url.qStr, 'qStr')#;
</cfoutput>
but didn't actually test the former method.
var qStr = '#url.qStr#';
... instead of this:
<cfoutput>
#toScript(url.qStr, 'qStr')#;
</cfoutput>
but didn't actually test the former method.
ASKER
great and thanks!
btw it does work with var qstr = '#qstr#' as well as toString ...
the urlencodedformat was the clincher i believe!
thanks again!
btw it does work with var qstr = '#qstr#' as well as toString ...
the urlencodedformat was the clincher i believe!
thanks again!
Cool, glad it worked out.
Thanks agx
ASKER
thank you too Rob!
Welcome @Rob :)