สอบถามการเรียกใช้งานตัวแปร ของJavaScript หรือ jQuery

คือผมต้องการเปลี่ยน function (ตัวอย่างที่ 1) นี้จากฟิกอ่านค่า(this.playList)ให้ไปอ่านจาก url ที่เป็น xml  แต่ผมลองเปลี่ยนเป็น ดังตัวอย่างที่ 2  ตัวแปร playlist ก็ไม่มีข้อมูลเข้ามาสักที่เลย

รบกวนด้วยนะครับ



ตัวอย่างที่ 1

function SceneVideoPlayerPartial(options){

                this.playList = [{

                                url: 'http://www.t.com/vdo/mn.mp4',

                                title: 'vdo 1',

                },{

                                url: 'http://www.t.com/vdo/mm.mp4',

                                title: 'vdo 2'

                }];

                function convCoord(val, baseResol) {

                                var rate = curWidget.height / baseResol;

                                return parseInt(val*rate, 10);

                }

}

ตัวอย่างที่ 2

function SceneVideoPlayerPartial(options){

                this.playList = [];

                $.ajax({

       type: "get"

       ,dataType: "xml"

       ,url: "http://www.sm.com/rss/vdo.xml"

       ,success: function(xml){

          alert("ParseForMobileXML $(xml).find(item).length > "+$(xml).find("item").length);

            if($(xml).find("item").length > 0){ // null check

           $(xml).find("item").each(function(){ // loop

            var t_title = $(this).find("title").text();

             var t_description = $(this).find("description").text();  

            var t_enclosure =  $(this).find("enclosure").attr('url');

             this.playList.push({

                      url: t_enclosure,

                      description: t_description,

                      title: t_title

            });

    });//end loop

     }// end null check

    }//end success

        ,error: function(){ alert("Read xml ["+url+"] error!!"); }

    });

}

 
29 พ.ค. 2556 4 1,773

อาจเป็นเพราะไม่มีอะไรตอบกลับจาก Server ก้ได้นะครับ เนื่องจาก Ajax ไม่สามารถโหลดข้าม Server ได้
#1

ขอบคุณนะครับ แต่ผมลอง alert ค่า t_title ในการวนลูปออกมาดูก็มานะครับ แต่พอผมจะเอา playList ออกมาใช้ กลับไม่มีอะไรมาครับ
#2

อืม ลองใช้ reference ดุครับ



var tmp = this;

....

$.ajax({.....,function(xml){

  ....

  tmp.playList.push(...);

}});
#3

ขอบคุณครับ เดี่ยวไปลองก่อนครับ
#4
ความคิดเห็น
ไฟล์อัปโหลด ชนิด jpg, jpeg ขนาดไฟล์ไม่เกิน 1024
^