简体   繁体   English

Firefox和Chrome,Opera上的jQuery Ajax问题(在Safari上运行良好)

[英]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.

相关问题 带load()的jquery-issue:适用于Firefox和Safari,不适用于Chrome,Opera和IE - jquery-issue with load(): works with Firefox and Safari, not with Chrome, Opera and IE jQuery .css()在IE 6,7,8和Firefox中不起作用,但在Chrome,Safari,Opera中起作用 - jQuery .css() not working in IE 6,7,8 and Firefox, but works in Chrome, Safari, Opera jQuery AJAX在任何IE中均不起作用,但在Firefox,Opera,Chrome和Safari中运行良好 - jQuery AJAX not working in any IE, but fine in Firefox, Opera, Chrome and Safari jQuery ajax可在Chrome中使用,但不能在Firefox或Safari中使用 - jQuery ajax works in Chrome, but not in Firefox or Safari jQuery ajax调用WebApi可在IE上运行,但不能在Firefox,Chrome或Opera上运行 - jQuery ajax call to WebApi works on IE but not Firefox, Chrome or Opera 我有用于通过ajax或jquery更新mysql的表,并且适用于firefox,opera,chrome和safari,但不适用于IE8 - I have table that i use to update mysql via ajax or jquery and works for firefox,opera,chrome and safari but not IE8 JavaScript可以在Chrome和Firefox中发布/正常运行,但不能在Safari中发布。 在Opera中有趣的作品 - JavaScript will post/work well in Chrome and Firefox, but not Safari. Works funny in Opera jQuery可以在Firefox,Safari和Opera中运行,但不能在IE中运行吗? - Jquery works in Firefox, Safari & Opera but not IE? jQuery代码在Firefox上有效,但在Chrome和Opera中不可用 - Jquery Code works on Firefox but not in Chrome & Opera jQuery ajax可在Chrome和Safari中使用,但不能在IE8和Firefox中使用 - Jquery ajax works in Chrome and Safari, but not in IE8 and Firefox
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM