<i id='sUBMd'><tr id='sUBMd'><dt id='sUBMd'><q id='sUBMd'><span id='sUBMd'><b id='sUBMd'><form id='sUBMd'><ins id='sUBMd'></ins><ul id='sUBMd'></ul><sub id='sUBMd'></sub></form><legend id='sUBMd'></legend><bdo id='sUBMd'><pre id='sUBMd'><center id='sUBMd'></center></pre></bdo></b><th id='sUBMd'></th></span></q></dt></tr></i><div id='sUBMd'><tfoot id='sUBMd'></tfoot><dl id='sUBMd'><fieldset id='sUBMd'></fieldset></dl></div>
      <bdo id='sUBMd'></bdo><ul id='sUBMd'></ul>
  • <tfoot id='sUBMd'></tfoot>
  • <small id='sUBMd'></small><noframes id='sUBMd'>

      1. <legend id='sUBMd'><style id='sUBMd'><dir id='sUBMd'><q id='sUBMd'></q></dir></style></legend>

        如何在客户端检查 YouTube 上是否存在视频

        How do I check if a video exists on YouTube, in client side(如何在客户端检查 YouTube 上是否存在视频)

                <tbody id='z0bWu'></tbody>

              • <bdo id='z0bWu'></bdo><ul id='z0bWu'></ul>

                <small id='z0bWu'></small><noframes id='z0bWu'>

                • <legend id='z0bWu'><style id='z0bWu'><dir id='z0bWu'><q id='z0bWu'></q></dir></style></legend>
                • <tfoot id='z0bWu'></tfoot>
                • <i id='z0bWu'><tr id='z0bWu'><dt id='z0bWu'><q id='z0bWu'><span id='z0bWu'><b id='z0bWu'><form id='z0bWu'><ins id='z0bWu'></ins><ul id='z0bWu'></ul><sub id='z0bWu'></sub></form><legend id='z0bWu'></legend><bdo id='z0bWu'><pre id='z0bWu'><center id='z0bWu'></center></pre></bdo></b><th id='z0bWu'></th></span></q></dt></tr></i><div id='z0bWu'><tfoot id='z0bWu'></tfoot><dl id='z0bWu'><fieldset id='z0bWu'></fieldset></dl></div>
                  本文介绍了如何在客户端检查 YouTube 上是否存在视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在

                  解决方案

                  @hitesh, 请从 ajax 请求中删除 datatype:'jsonp'.这样,如果视频 id 可用,您将获得 json 字符串,如果它不可用,则将调用 ajax 错误回调.我试过你的小提琴及其工作.试试这样-

                  //var videoID = 'kn8yzJITdvI';//不工作var videoID = 'p4kIwWHP8Vc';//工作$.ajax({url: "https://gdata.youtube.com/feeds/api/videos/" + videoID + "?v=2&alt=json",//数据类型:jsonp",成功:函数(数据){控制台日志(数据)$("#result").text(data);},错误:函数(jqXHR,textStatus,errorThrown){//这里处理错误alert('错误:' + textStatus);}});

                  这是您需要的解决方案的另一个简短实现-

                  //var videoID = 'kn8yzJITdvI';//不工作var videoID = 'p4kIwWHP8Vc';//工作$.getJSON('http://gdata.youtube.com/feeds/api/videos/'+videoID+'?v=2&alt=jsonc',function(data,status,xhr){警报(data.data.title);}).error(function() { alert("error"); });

                  I am doing validation for my Youtube url text field.

                  I need to check, if the Youtube url does not exist I should throw error, I followed this answer and created the jsfiddle to check it.

                  It works for valid url but it does not work for invalid url. All I see is 404 error in network console

                  Is there a way to check if url exist in client side using JavaScript and jQuery.

                  here is my code :

                  var videoID = 'kn8yzJITdvI';//not working 
                  //var videoID = 'p4kIwWHP8Vc';//working 
                  $.ajax({
                      url: "https://gdata.youtube.com/feeds/api/videos/" + videoID + "?v=2&alt=json",
                      dataType: "jsonp",
                      success: function(data) {
                          console.log(data)
                            $("#result").text(data);
                      },
                      error: function(jqXHR, textStatus, errorThrown)
                                      {
                                          // Handle errors here
                                          alert('ERRORS: ' + textStatus);
                  
                                      }
                  });
                  

                  JSfiddle Link

                  解决方案

                  @hitesh, Please remove the datatype:'jsonp' from the ajax request. This way you'll get json string if the video id is available and if its not available then the ajax error callback would be invoked. I tried on your fiddle and its working. Try like this-

                  //var videoID = 'kn8yzJITdvI';//not working 
                  var videoID = 'p4kIwWHP8Vc';//working 
                  $.ajax({
                      url: "https://gdata.youtube.com/feeds/api/videos/" + videoID + "?v=2&alt=json",
                      //dataType: "jsonp",
                      success: function(data) {
                          console.log(data)
                            $("#result").text(data);
                      },
                      error: function(jqXHR, textStatus, errorThrown)
                                      {
                                          // Handle errors here
                                          alert('ERRORS: ' + textStatus);
                                      }
                  });
                  

                  Here is another short implementation for the solution you need-

                  //var videoID = 'kn8yzJITdvI';//not working 
                  var videoID = 'p4kIwWHP8Vc';//working 
                  
                  $.getJSON('http://gdata.youtube.com/feeds/api/videos/'+videoID+'?v=2&alt=jsonc',function(data,status,xhr){
                      alert(data.data.title);
                  }).error(function() { alert("error"); });
                  

                  这篇关于如何在客户端检查 YouTube 上是否存在视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Pause youtube video, youtube api(暂停 youtube 视频,youtube api)
                  Youtube iframe api not triggering onYouTubeIframeAPIReady(Youtube iframe api 未触发 onYouTubeIframeAPIReady)
                  How can I stop a video with Javascript in Youtube?(如何在 Youtube 中停止使用 Javascript 的视频?)
                  How to call Greasemonkey#39;s GM_ functions from code that must run in the target page scope?(如何从必须在目标页面范围内运行的代码中调用 Greasemonkey 的 GM_ 函数?)
                  How do you mute an embedded Youtube player?(如何使嵌入式 Youtube 播放器静音?)
                  How to get number of video views with YouTube API?(如何使用 YouTube API 获取视频观看次数?)
                          <tfoot id='NIBsM'></tfoot>
                        1. <legend id='NIBsM'><style id='NIBsM'><dir id='NIBsM'><q id='NIBsM'></q></dir></style></legend>
                            <tbody id='NIBsM'></tbody>

                          <small id='NIBsM'></small><noframes id='NIBsM'>

                        2. <i id='NIBsM'><tr id='NIBsM'><dt id='NIBsM'><q id='NIBsM'><span id='NIBsM'><b id='NIBsM'><form id='NIBsM'><ins id='NIBsM'></ins><ul id='NIBsM'></ul><sub id='NIBsM'></sub></form><legend id='NIBsM'></legend><bdo id='NIBsM'><pre id='NIBsM'><center id='NIBsM'></center></pre></bdo></b><th id='NIBsM'></th></span></q></dt></tr></i><div id='NIBsM'><tfoot id='NIBsM'></tfoot><dl id='NIBsM'><fieldset id='NIBsM'></fieldset></dl></div>
                            <bdo id='NIBsM'></bdo><ul id='NIBsM'></ul>