sebtn
August 8, 2016, 12:20am
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
Any pointers are much appreciated.
myApp
Seb
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.
1 Like
sebtn
August 8, 2016, 12:35pm
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
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.
sebtn
August 8, 2016, 12:59pm
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?
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).
1 Like