Getting empty string on tweeter button

Getting empty string on tweeter button
0

#1

Hi,

I’m having a bit of trouble because the string used to generate the tweeter address are returning empty so nothing gets passed to the dialog box to re tweet. Does anybody have a clue how to debug this?

$(’#text-quote’).text = " "

$(’#text-quote’).val = null

:cold_sweat:

Any pointers are much appreciated.

myApp

Seb


#2

Hi, @sebtn. Maybe you meant .text() (note the parentheses)?

I added a line in your code

$('#text-quote').html(post.content);
$('#autor').html(post.title);

// this line modifies the tweet link's `href` attribute.
$('#tweet').attr('href', 'http://twitter.com/intent/tweet?text=' + $('#text-quote').text() + $('#autor').text());

I also removed the line with the window.open(...) at the end of your code, since all it does is opens a new window at page load.


#3

Hi,

Thanks for the reply.

Sorry but still doesn’t work, the twitter page comes back empty which means,
$(’#text-quote’).text() + $(’#autor’).text()) is still returning an empty string, which is wierd


#4

The line

$('#tweet').attr('href', 'http://twitter.com/intent/tweet?text=' + $('#text-quote').text() + $('#autor').text());

has to after the line $('#autor').html(post.title);.

You may have misread the code I posted. They all go together.


#5

ahh ok, now it works. Thanks

Why doesn’t it work if it is outside the ajax request? What are the rules of thumb on the scope?


#6

That line executes right at page load, during which both $('#text-quote') and $('#autor') still has empty strings as text.

In your case you want to change the href every time the quote is changed (i.e., every ajax request).