กรุณาปิด AdBlock!

Cancel your adBlock please.

ขยายหน้าเว็บRegister Login
 โฆษณา
หน้า: [1]  ลงล่าง
  พิมพ์  
topic

วิธีทำ radio online ให้โชว์เพลงที่กำลังเปิดแบบไม่ใช้ iframe  (อ่าน 12755 ครั้ง)

ไอที
« เมื่อ: 18, 02 2010, 01:26:11 PM »
อ้างเนื้อหาที่ใช้
Jquery : setInterval or setTimeout
I was doing a live counter for some of my sites … so to make it “LIVE” I’ve used the Great Jquery library (if you dont know what’s jquery is … i will make a post soon about it and some JQUERY For dummies post)

What i have is simple :

- count.php // the counter basically it’s just a php file where i update the database
- index.php // the main page where i show the counter .

so this is what i wrote on the index.php
// The call to the count.php page , Using Post Method and sending 1 as a variable
function update() {
 
$.
post("count.php", {count:1},
  function(
data){
   $(
"#counter").html(data);});
}
 
// The code that call the update function each seconds
  
$(document).ready(function() {
    
setInterval("update()"1000);
  })

So after writing this code , everything was working fine and the counter was live and the update worked .

I asked in few forums to see if there was any problem with my code since i’m new to jquery

here are some of the answers i got :

From a Sitepoint member hexburner
อ้างถึง
You could use an Ajax request with the if Modified header.

Or you could just use the load function.

The one second interval creates a huge amount of requests, which I wouldn’t recommend…

Nobody is really looking to the counter every second, so you can increase the interval without upsetting anybody.

What really concerns me is what happens if counter.php could not be loaded within the one second interval.

Imagine someones internet connection breaks down right after they visit your website.

The page counter.php could not be loaded, and after 30 seconds you’ll have 30 open connections…

So don’t use setInterval with ajax requests, but rather use setTimeout after the ajax request completed or returned an error.

I would recommend something like below, but you could use one of the other ajax functions of jQuery, whichever suits you best.

jQuery(document).ready(loadCounter);
 
function 
loadCounter () {
    $(
"#counter").load("count.php", {count:1}, function(responseTexttextStatusXMLHttpRequest){
        
setTimeout(loadCounter5000);
    });
}

I tested his code and everything was fine and working .

The only concern i’m still having is the server issue , since the site is on a shared account … here is what another person from Google jquery group answered ”
อ้างถึง
If this is what you are after, and you are getting that data from a database, then a request must be sent every time to that database.

Seems to be pretty taxing, especially if traffic ramps up.

Joe

he’s right , in worse case what i will do is one of the followings :

- Make the call every 5 seconds instead of 1
- Make the call only on click call

Any other ideas for live counter ?

what about the live chat i think it’s the same idea behind …

---
จองไว้ก่อนเดี๋ยวมาเขียนต่อ
เด็กไอทีคลับ
เด็กไอทีตัวพ่อ
เด็กไอทีคลับชั้นเซียน
*
พลังความคิด 89
กระทู้: 3,536
บันทึกการเข้า
ไอที
« ตอบ #1 เมื่อ: 18, 02 2010, 03:43:51 PM »
ว้าวสุดยอดเลยค่ะ ที่รักเราเก่งมาก

ดีด้วยค่ะอันนี้ ถึงมันจะช้าไปนิดก็เถอะนะ
CoolPha
RUK-YOM
ปรมาจารย์ด้านไอที
*
พลังความคิด 76
กระทู้: 5,261
เว็บไซต์
บันทึกการเข้า

ไอที
« ตอบ #2 เมื่อ: 4, 03 2010, 05:27:19 PM »
อยากบอกว่า  "มันเจ๋งมากๆๆๆ"
อิอิ ขอบคุณครับ
CyberNoi
ยามเฝ้าบอร์ด
เด็กไอทีคลับไฟแรง
*
พลังความคิด 15
กระทู้: 167
เว็บไซต์
บันทึกการเข้า

เด็กไทยหัวใจ IT เด้อ
ไอที
« ตอบ #3 เมื่อ: 4, 03 2010, 08:11:44 PM »
ป็อด สอบเสร็จ ยังอ่ะจ้ะ

มาบ่อย ๆ สิ
CoolPha
RUK-YOM
ปรมาจารย์ด้านไอที
*
พลังความคิด 76
กระทู้: 5,261
เว็บไซต์
บันทึกการเข้า

ไอที
« ตอบ #4 เมื่อ: 5, 03 2010, 11:20:14 AM »
สอบ 8-9 มีนา  ครับบบบ อิอิอิ
ช่วงนี้ยุ่งมากเลยครับ  หลายงาน เหอะๆๆๆ
แต่ยังไงจะมาบ่อยๆๆ แบ่งปันน้ำใจกันนน นะครับ อิอิ
CyberNoi
ยามเฝ้าบอร์ด
เด็กไอทีคลับไฟแรง
*
พลังความคิด 15
กระทู้: 167
เว็บไซต์
บันทึกการเข้า

เด็กไทยหัวใจ IT เด้อ
ไอที
« ตอบ #5 เมื่อ: 29, 03 2010, 05:49:34 PM »
จะลองเอาไปทำดูดีกว่า
paemam
เด็กไอทีคลับหน้าใหม่
*
พลังความคิด 3
กระทู้: 17
เว็บไซต์
บันทึกการเข้า

เว็บนี้เป็นเว็บทำงานที่ได้เงินจริงๆคับเด็กไอทีน่าจะเข้ามาดูนะคับ
                    www.yakuzaa.ws link
 เพิ่มโอกาสทางการตลาด และเพิ่มรายได้ จากการใช้ประโยชน์ทาง
                          อินเตอร์เน็ท
ไอที
« ตอบ #6 เมื่อ: 30, 03 2010, 08:11:19 PM »
อืม ลองทำดูค่ะ

บวก หนึ่งให้แล้วนะค่ะ

ยินดีต้อนรับค่ะ
CoolPha
RUK-YOM
ปรมาจารย์ด้านไอที
*
พลังความคิด 76
กระทู้: 5,261
เว็บไซต์
บันทึกการเข้า

หน้า: [1]  ขึ้นบน
  พิมพ์  
 
กระโดดไป: