显示JW播放器

时间:2013-03-26 17:37:03

标签: php ajax jwplayer

我的页面有文本输入和按钮 用户必须在文本字段中填写引用可播放媒体文件(mp4)的URL,然后单击按钮

单击该按钮时,脚本正在运行,并且ajax将url值传递给PHP文件,该文件会进行一些验证并将响应发送回来

如果一切正常,它应该用JW播放器替换DIV标签,用户可以播放媒体

我通过用纯文本或图像替换DIV标签来测试整个过程,并且它运行顺畅

当我尝试用jw播放器组件替换它时,它没有显示任何东西

我通过直接在HTML代码中插入jw来测试jw,它运行顺利

这里是完整的index.html

    <!DOCTYPE html>
    <html>
    <head>
    <script type="text/javascript" src="/ajax4/jwplayer.js"></script>
    <script type="text/javascript">jwplayer.key="RXVe0CXFsIS8pAar5ezgSLJqb9jfx7rDOBxkVw==";</script>
    <script type="text/javascript"><!--

    function get_XmlHttp() {
      var xmlHttp = null;

      if(window.XMLHttpRequest) {       // for Forefox, IE7+, Opera, Safari, ...
        xmlHttp = new XMLHttpRequest();
      }
      else if(window.ActiveXObject) {   // for Internet Explorer 5 or 6
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }

      return xmlHttp;
    }

    // sends data to a php file, via POST, and displays the received answer
    function ajaxrequest(php_file, tagID) {
      var request =  get_XmlHttp();     // call the function for the XMLHttpRequest instance

      // create pairs index=value with data that must be sent to server
      var hiturl = document.getElementById('hit').value;
      var  the_data = 'hiturl='+hiturl;

      request.open("POST", php_file, true);         // set the request

      // adds  a header to tell the PHP script to recognize the data as is sent via POST
      request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      request.send(the_data);       // calls the send() method with datas as parameter

      // Check request status
      // If the response is received completely, will be transferred to the HTML tag with tagID
      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          document.getElementById(tagID).innerHTML = request.responseText;
        }
      }
    }
    --></script>

    </head>
    <body>
    <form action="test_form.php" method="post" name="form1" onsubmit="ajaxrequest('hitphp.php', 'myDiv'); return false;">
    <label for="name" id="name_label">hit URL: </label>  
    <input type="text" name="hit" id="hit" size="100"  /> 
    <input type="submit" value="Enter hit UrL" />

    </form>
    <div id="myDiv"></div>

    </body>
    </html>

和hitphp.php文件

    <?php
    // if data are received via POST
    if (isset($_POST['hiturl'])) {
      // get data into variables, deleting the html tags
      $hiturl = strip_tags($_POST['hiturl']);

      // if the form fields are completed
      if (true) {
        if (true) {


    echo'<div id="myElement">nnnnn.....</div><script type="text/javascript">
jwplayer("myElement").setup({

    type:"mp4", 
    bufferlength: "60",
    file: "mediaurl",


});


</script>';



}else{
echo 'sorry not a valid url';
}
      }
      else {
        echo 'Fill in all form fields';
      }
    }
    ?> 

0 个答案:

没有答案