Hey all Im have trouble passing this jquery functions results thru an ajax call.
I want this function:

$('.sidebar_bookmark_linkrel1').attr('href')

to pass as string, any ideas?

hi soapyillusion,

Shouldn't the function already pass a string? jQuery ATTR
My guess here, since the selector you used is a class(and no reference HTML code was shown), it returns multiple elements or no element, and you were expecting only one(?). But then it resulted to getting value from an unexpected element with an href attribute or an element without an href.

Have you seen the value returned by $('.sidebar_bookmark_linkrel1').attr('href')? what it "undefined", relative path, or an absolute?

One way to check it is by alert($('.sidebar_bookmark_linkrel1').attr('href')), let's start from there.

When I do an alert it returns just fine, problem is when the callback sends the data to the php function in my cakePHP controller. It keeps on switching to some bizzare array where part of the url is the index and the other the value. I thought it was a php problem but Im able to pass a normal string with no difficulty from javascript and as well as other jquery functions.

If it's ok for you, can you please post the part of you JS code where you send the data. It'll be best if you post the JS part where you process the $('.sidebar_bookmark_linkrel1').attr('href') up to sending your data through AJAX. How's do you format the data anyway?

You can encode the sent URL like this,

var encodedHREF;
encodedHREF = encodeURIComponent(yourHREFValue);

before sending it, to make it more friendly. Then you can just decode it like this:

$decodedURL = "";

$decodedURL = urldecode($varibleToYourHREF);

and process it from there.

I think I solved the problem well for the mean time. Set up a new attribute within the href html tag, and use jquery to read that in. As of now, cakephp seems to be passing it as an int no problem. So Ive been able to use that in my database calls once the user clicks on said link . If it stays working... cakephp hasnt been nice to me or my component lol.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.