我正在制作ajax jsonp请求,但失败错误处理不起作用.如果请求是404或500,它将无法处理错误.
我一直在寻找答案,但找不到任何答案.http://code.google.com/p/jquery-jsonp/似乎有一个解决方案,但我找不到任何关于如何使用它的示例.
function authenticate(user, pass) {
$.ajax ({
type: "POST",
url: "url",
dataType: 'jsonp',
async: false,
//json object to sent to the authentication url
data: {"u": userid, "p": pass},
success: function (data) {
//successful authentication here
console.log(data);
},
error: function(XHR, textStatus, errorThrown) {
alert("error: " + textStatus);
alert("error: " + errorThrown);
}
})
}
Run Code Online (Sandbox Code Playgroud) 我试图访问一个404事件,我可以看到回来作为404与firebug,但错误功能没有踢,用我的下面的代码我总是得到错误:成功?
即.
$.ajax({
type: 'get',
url: 'url: 'https://admin.instantservice.com/resources/smartbutton/5702/10945/available.gif?' + Math.floor(Math.random()*10001),
success: function(data, textStatus, XMLHttpRequest){
console.log('Error: ' + textStatus);
},
error:function (xhr, ajaxOptions, thrownError){
alert(xhr.status);
alert(xhr.statusText);
alert(xhr.responseText);
}
});
Run Code Online (Sandbox Code Playgroud)
我再次知道1000%,我在firebug中获得404 Not Found,它永远不会触发错误.
我错过了什么吗?
我必须创建一个文本框,只允许你管视频的网址.
要在服务器端处理验证,我使用下面的代码
$rx = '~
^(?:https?://)? # Optional protocol
(?:www\.)? # Optional subdomain
(?:youtube\.com|youtu\.be) # Mandatory domain name
/watch\?v=([^&]+) # URI with video id as capture group 1
~x';
$has_match = preg_match($rx, $url, $matches);
Run Code Online (Sandbox Code Playgroud)
我正在为客户端验证寻找相同的解决方案.我在<input type="url"> 这里找到了 ,但它似乎只适用于html5浏览器.
是否可以使用文本框进行客户端验证,以便与所有浏览器兼容?
谢谢
我想在我的网页上添加动态YouTube视频嵌入功能,即用户在文本框中输入youtube url后,如果网址有效,则视频会自动嵌入输入框下方.
我认为这可以用jquery完成,我最不知道.所以请相应地帮助我.任何精心设计的帮助都非常感谢.