Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.


1818 posts

Uber Geek
+1 received by user: 52

Trusted

Topic # 59805 12-Apr-2010 23:55
Send private message

I am a bad coder and am writing some shocking code that I build by googling until it worked.

My current bit of php is a twitter tool that uses jquery to load() in tweet threads on demand.

I've got the base code from the jquery .load() page

And looks like this


$("#clicks").click(function(){
$("#success").load("getTweet.php",{id:7245855505}, function(response, status, xhr ) {
if (status == "error") {
var msg = "Sorry but there was an error: ";
alert(msg + xhr.status + " " + xhr.statusText);
}
});
});

So my problem is, the above will have to be duplicated for each tweet that is a reply,
is there a way around the duplication as it will make the code look messy as with lumps of JS generated through out the page. Or is it ok to have a mess behind the scene if the user up front likes its function.

Create new topic
Infrastructure Geek
4056 posts

Uber Geek
+1 received by user: 195

Trusted
Microsoft NZ
Subscriber

  Reply # 317589 13-Apr-2010 01:34
Send private message

what about a combo of regular javascript and jquery? use the 'this' operator in the onclick to pass the current element context to the js function. grab the id and innerText (or whatever) and manipulate from there

script
function getTweet(obj){
$(#obj.id).load('getTweet.php','id:' + obj.innerText + '}', blah....
}
/script

div onclick='getTweet(this)' 7245855505 /div

As far as the end use goes, they wont care as long as it works. As a developer, less is always more. As far as speed goes, loading 100 lines of text/javascript instead of 10 probably isnt going to make much diff bandwidth wise, but it may slow a little in the browser depending on the script and the jit compiler. If you have a javascript scanning antivirus engine installed then the page loads could become considerably worse.




Technical Evangelist
Microsoft NZ
about.me/nzregs
Twitter: @nzregs




1818 posts

Uber Geek
+1 received by user: 52

Trusted

  Reply # 317896 13-Apr-2010 16:21
Send private message

Thanks Regs, been learning some more about JS from trying to understand what JS is doing from your code and I'm slowly getting there. Got the $('#'+obj.id).load sorted and should work out great.


function getTweet(obj){
$('#'+ obj.id).load("getTweet.php",{id:+obj.id}, function(response, status, xhr ) {
if (status == "error") {
var msg = "Sorry but there was an error: ";
alert(msg + xhr.status + " " + xhr.statusText);
}
});
};

Create new topic

Twitter »

Follow us to receive Twitter updates when new discussions are posted in our forums:



Follow us to receive Twitter updates when news items and blogs are posted in our frontpage:



Follow us to receive Twitter updates when tech item prices are listed in our price comparison site:





News »

N4L helping TAKA Trust bridge the digital divide for Lower Hutt students
Posted 18-Jun-2018 13:08


Winners Announced for 2018 CIO Awards
Posted 18-Jun-2018 13:03


Logitech Rally sets new standard for USB-connected video conference cameras
Posted 18-Jun-2018 09:27


Russell Stanners steps down as Vodafone NZ CEO
Posted 12-Jun-2018 09:13


Intergen recognised as 2018 Microsoft Country Partner of the Year for New Zealand
Posted 12-Jun-2018 08:00


Finalists Announced For Microsoft NZ Partner Awards
Posted 6-Jun-2018 15:12


Vocus Group and Vodafone announce joint venture to accelerate fibre innovation
Posted 5-Jun-2018 10:52


Kogan.com to launch Kogan Mobile in New Zealand
Posted 4-Jun-2018 14:34


Enable doubles fibre broadband speeds for its most popular wholesale service in Christchurch
Posted 2-Jun-2018 20:07


All or Nothing: New Zealand All Blacks arrives on Amazon Prime Video
Posted 2-Jun-2018 16:21


Innovation Grant, High Tech Awards and new USA office for Kiwi tech company SwipedOn
Posted 1-Jun-2018 20:54


Commerce Commission warns Apple for misleading consumers about their rights
Posted 30-May-2018 13:15


IBM leads Call for Code to use cloud, data, AI, blockchain for natural disaster relief
Posted 25-May-2018 14:12


New FUJIFILM X-T100 aims to do better job than smartphones
Posted 24-May-2018 20:17


Stuff takes 100% ownership of Stuff Fibre
Posted 24-May-2018 19:41



Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.

Alternatively, you can receive a daily email with Geekzone updates.