html jQuery,AJAX:即时AJAX搜索(Bonus:SoundCloud API搜索)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html jQuery,AJAX:即时AJAX搜索(Bonus:SoundCloud API搜索)相关的知识,希望对你有一定的参考价值。

jQuery(document).ready(function($) {

	$("#search").keyup(function(){
	    // get the search form value
		var formData = $("#search").val();

		// clear search results div
		$('#getpocket').html('');

		// find all tracks with the genre 'punk' that have a tempo greater than 120 bpm.
		SC.get('/tracks', { q: formData, duration: { from: 3000000 }, limit: '40' }, function(tracks) {

			for (var i=0, len=tracks.length; i < len; i++) {
				$('#getpocket').append('<div>' + '<a href="' + tracks[i].permalink_url + '">' + tracks[i].title + '</a>'+ '</div><br>');

				var track_url = tracks[i].permalink_url;
				var player = SC.oEmbed(track_url, { auto_play: true } );

				$('#getpocket').html(player);
			}
		});

		return false;
	});

});
<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title></title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <!-- Place favicon.ico and apple-touch-icon.png in the root directory -->

        <link rel="stylesheet" href="css/normalize.css">
        <link rel="stylesheet" href="css/main.css">
        <script src="js/vendor/modernizr-2.6.2.min.js"></script>
    </head>
    <body>
        <!--[if lt IE 7]>
            <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
        <![endif]-->

        <!-- SoundCloud API -->
        <script src="//connect.soundcloud.com/sdk.js"></script>
        <script>
          SC.initialize({
            client_id: " insert your client ID",
            redirect_uri: " insert redirect URL",
          });
        </script>
        <!-- SoundCloud API End -->

        <h1>Search soundCloud:</h1>
        <form action="index_submit" method="get" accept-charset="utf-8">
            <input id="search" type="search" name="search">
            <input id="submit" type="button" name="submit" value="Search">
        </form>
        
        <!-- Here we display AJAX search results -->
        <div id="getpocket"></div>

        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.10.2.min.js"><\/script>')</script>
        <script src="js/plugins.js"></script>
        <script src="js/main.js"></script>

    </body>
</html>

以上是关于html jQuery,AJAX:即时AJAX搜索(Bonus:SoundCloud API搜索)的主要内容,如果未能解决你的问题,请参考以下文章

为 AJAX 请求在 jQuery 中对字符串进行 URL 编码

ajax短轮询+php与服务器交互制作简易即时聊天网站

axios封装-队列管理

利用ajax短轮询+php与服务器交互制作简易即时聊天网站

通过在 MVC 中使用 Jquery 和 ajax 进行搜索来获取 html 表中的值

在 django 中需要有关 ajax 和 jquery 搜索表单的帮助