- When I try the code below in Cassini, I get a valid response.
- When I make the following RESTful call in a browser, I see a valid response -
http://api.brightcove.com/services/library?command=find_all_videos&page_size=1&video_fields=name&token=[token]
. - But when I host my website in IIS 7.5, my callback function receives a
null
argument.
My Question:
Could IIS 7.5 be blocking the response?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
function validateReadToken() {
$.getJSON("http://api.brightcove.com/services/library?command=find_all_videos&page_size=1&video_fields=name&token=[token]",
function (data) {
alert(data.items.length);
}
);
}
开发者_如何转开发 $(document).ready(function () {
$("a").click(function (event) {
validateReadToken();
});
});
</script>
</head>
<body>
<a href="javascript:void(0)">Test</a>
</body>
</html>
Might be worth reading through this: http://support.brightcove.com/en/docs/using-xmlhttp-make-calls-proxy.
I'm not an AJAX expert but hosting your site on your own IIS server and then making service requests against brightcove would seem to fall under the umbrella of cross domain issues.
Perhaps trying a server-side proxy would be the way forward.
Cheers, Dan
Thanks for everyone's help.
Indeed, I needed to pay attention to the fact that I was trying to make a cross-domain request.
To get around this limitation, I need to use JSONP.
- JSONP Explanation 1
- JSONP Explanation 2
- Concise Code Example
New Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
function validateReadToken() {
var url = 'http://api.brightcove.com/services/library?command=find_all_videos&page_size=1&video_fields=name&token=[token]';
$.getJSON(url + "&callback=?", function (data) {
alert(data.items.length);
});
}
$(document).ready(function () {
$("a").click(function (event) {
validateReadToken();
});
});
</script>
</head>
<body>
<a href="javascript:void(0)">Test</a>
</body>
</html>
精彩评论