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.


hellonearthisman

1819 posts

Uber Geek

Trusted

#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
Regs
4064 posts

Uber Geek

Trusted
Snowflake

  #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.




 
 
 

Free kids accounts - trade shares and funds (NZ, US) with Sharesies (affiliate link).
hellonearthisman

1819 posts

Uber Geek

Trusted

  #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





News and reviews »

NordVPN Helps Users Protect Themselves From Vulnerable Apps
Posted 5-Dec-2023 14:27


First-of-its-Kind Flight Trials Integrate Uncrewed Aircraft Into Controlled Airspace
Posted 5-Dec-2023 13:59


Prodigi Technology Services Announces Strategic Acquisition of Conex
Posted 4-Dec-2023 09:33


Samsung Announces Galaxy AI
Posted 28-Nov-2023 14:48


Epson Launches EH-LS650 Ultra Short Throw Smart Streaming Laser Projector
Posted 28-Nov-2023 14:38


Fitbit Charge 6 Review 
Posted 27-Nov-2023 16:21


Cisco Launches New Research Highlighting Gap in Preparedness for AI
Posted 23-Nov-2023 15:50


Seagate Takes Block Storage System to New Heights Reaching 2.5 PB
Posted 23-Nov-2023 15:45


Seagate Nytro 4350 NVMe SSD Delivers Consistent Application Performance and High QoS to Data Centers
Posted 23-Nov-2023 15:38


Amazon Fire TV Stick 4k Max (2nd Generation) Review
Posted 14-Nov-2023 16:17


Over half of New Zealand adults surveyed concerned about AI shopping scams
Posted 3-Nov-2023 10:42


Super Mario Bros. Wonder Launches on Nintendo Switch
Posted 24-Oct-2023 10:56


Google Releases Nest WiFi Pro in New Zealand
Posted 24-Oct-2023 10:18


Amazon Introduces All-New Echo Pop in New Zealand
Posted 23-Oct-2023 19:49


HyperX Unveils Their First Webcam and Audio Mixer Plus
Posted 20-Oct-2023 11:47









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.