weixin_33717117 2015-12-18 04:44 采纳率: 0%
浏览 26

向Apple请求视频

I am a complete newbie to programming and am working on a sample project. I am trying to send an AJAX request to Apple to get a video from a user-defined artist. However, I don't get any data returned to my function and nothing shows up in the console.

Index.php

<!DOCTYPE html>
<html>
<head>
    <title>iTunes Video Search</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $('form').submit(function() {
                $.post($(this).attr('action'), $(this).serialize(), function(res) {
                    var htmlStr = '';
                    if (res.results.length !== 0) {
                        htmlStr += "<video controls src='" + res.results[0].previewUrl + "'></video>";
                    } else {
                        htmlStr += "Not Found";
                    }
                    $('#video').html(htmlStr);
                }, 'json');
                return false;
            });
        });
    </script>
</head>
<body>
    <h2>Enter Artist's Name</h2>
    <form action="/videos/create" method="post">
        <input type="search" name="artist_name" id="artist_name">
        <input type="submit" value="Search">
    </form>
    <div id="video"></div>
</body>
</html>

Videos.php

<?php

class Videos extends CI_Controller {

    public function index() {
        $this->load->view('index');
    }

    public function create() {
        $artist_name = str_replace(' ', '', $this->input->post('artist_name'));
        $url = "https://itunes.apple.com/search?term=" . $artist_name . "&entity=musicVideo";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        $data = curl_exec($ch);
        $info = curl_getinfo($ch);
        curl_close($ch);
        echo $data;
    }
}

?>

Any help is greatly appreciated!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 对于这个问题的解释说明
    • ¥200 询问:python实现大地主题正反算的程序设计,有偿
    • ¥15 smptlib使用465端口发送邮件失败
    • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
    • ¥15 对于squad数据集的基于bert模型的微调
    • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
    • ¥20 steam下载游戏占用内存
    • ¥15 CST保存项目时失败
    • ¥20 java在应用程序里获取不到扬声器设备
    • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。