[英]jQuery Ajax problems on Firefox and Chrome, Opera (works well on Safari)
I have a small code of HTML with jQuery. 我有一个带有jQuery的HTML小代码。 In my code, i call a simple ajax call. 在我的代码中,我调用了一个简单的ajax调用。 It's works well on Safari but did work on Firefox and Chrome. 它在Safari上运行良好,但在Firefox和Chrome上运行良好。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>untitled</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Daniel">
<!-- Date: 2011-11-07 -->
<script type='text/javascript' src='http://media.smashingmagazine.com/themes/smashing/js/jquery-1.5.2.min.js?ver=3.1.3'></script>
<script type='text/javascript' src='http://media.smashingmagazine.com/themes/smashing/js/jquery-ui-1.8.2-min.js?ver=3.1.3'></script>
</head>
<script type="text/javascript">
var jwt = "";
var certUrl = "";
function getJwt() {
$.get(
"http://signerapp.appspot.com/signerapp",
function(data) { jwt = data;}
);
}
function checkAvailable() {
var postObject = {};
postObject.certUrl = certUrl;
postObject.jwt = jwt;
postObject.action = "available";
postObject.shortUrl = $('#shortUrl').attr('value');
$.ajax( {
url: "http://clickin-shorturl.appspot.com/urlshortener/v1/url",
type: "POST",
data: JSON.stringify(postObject),
success: function(data) { alert(data); }
});
}
$(document).ready(function() {
getJwt();
});
</script>
<body>
</br>
</br>
</br>
</br>
</br>
<h4>This is sample for creating url shortener</h4>
<p>Check available:</p>
<div>
<!-- Check availability-->
<table border="1" width="540" height="100%">
<!-- Check availability-->
<tr>
<td>
<form>
Action: <input type="textbox" id="action1" name="action1" value="available" disabled="disabled" size="20"></br>
Short URL: <input type="textbox" id="shortUrl" name="shortUrl" value="aaaa" size="20"></br>
<input type="button" id="checkButton" name="checkButton" value="Check Available" onClick="checkAvailable();"></br>
</form>
</td>
</tr>
<tr>
</table>
</div>
</body>
</html>
Problem is with calling to $.get and $.ajax above. 问题在于调用上面的$ .get和$ .ajax。 With Safari, i get the accurate result: a base64 string at $.get and json at $.ajax But with Firefox i can not receive anything Although the response code is "200 OK", the body did contain anything. 使用Safari,我可以得到准确的结果:$ .get的base64字符串和$ .ajax的json。但是使用Firefox,我什么也收不到,尽管响应代码为“ 200 OK”,但正文确实包含任何内容。
this is because of the same origine policy . 这是因为相同的原始政策 。 you cannot load other website content using ajax request. 您不能使用ajax请求加载其他网站内容。 if you want to do that, you have to use JSONP for this. 如果要这样做,则必须为此使用JSONP。 or you can use server side proxy for this. 或者您可以为此使用服务器端代理。
您可以使用firefox的firebug或chrome的inspect元素查找有关该错误的更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.