jQuery ajax在IE中不起作用
我在WebLogic 10.3.2上运行的Web应用程序中使用jQuery 1.7.1。我做ajax GETs到服务器。这在FF和Chrome中都可以正常工作,但IE8中的ajax事件没有发生任何反应。就好像文档已经准备好了一样。jQuery ajax在IE中不起作用
这里的有些JS:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="css/messaging.css" />
<link rel="stylesheet" type="text/css" href="css/jquery-ui-1.8.17.custom.css" />
<link rel="stylesheet" type="text/css" href="css/ui.dynatree.css" />
<link rel="stylesheet" type="text/css" href="css/jquery.cluetip.css" />
<link rel="stylesheet" type="text/css" href="css/jquery-ui-timepicker-addon.css" />
<script type="text/javascript" src="js/jquery-1.7.1.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.17.custom.min.js"></script>
<script type="text/javascript" src="js/jquery.dynatree.js"></script>
<script type="text/javascript" src="js/jquery.cookies.2.2.0.js"></script>
<script type="text/javascript" src="js/jquery.cluetip.js"></script>
<script type="text/javascript" src="js/jquery-ui-timepicker-addon.js"></script>
<script type="text/javascript" src="js/jquery-ui-sliderAccess.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$.ajaxSetup ({
cache: false,
xhrFields: {
withCredentials: true
},
crossDomain: true
});
...
$('#findSites').click(function() { // Locate HTML DOM element with ID "somebutton" and assign the following function to its "click" event...
searchVal = document.getElementById("searchFor").value;
searchTyp = document.getElementById("searchType").value;
$.get('SiteSearchServlet', {searchFor: searchVal, searchType: searchTyp}, function(responseJson) { // Execute Ajax GET request on URL of "someservlet" and execute the following function with Ajax response JSON...
...
我已经尝试过离开的字符集,只使用缓存=在ajaxsetup假的 - 没有帮助。当点击findSites按钮时,$ .get ajax调用不会执行。
谁能告诉我让jQuery ajax GETs在IE上工作的秘密吗?
尝试使用$ .ajax而不是$ .get,这样您可以添加一个错误回调并查看为什么ajax调用失败。
http://net.tutsplus.com/tutorials/javascript-ajax/5-ways-to-make-ajax-calls-with-jquery/ (见最后...在最后一节)
谢谢 - 我添加了“.error(function(jqXHR,textStatus,errorThrown){alert(”Error:“+ errorThrown);})”改为我的$ .get(真的是同一件事)并且出现“no transport”错误。谷歌搜索称这涉及到跨域问题。然后,我添加了这一行来强制IE允许这样做:“jQuery.support.cors = true; //强制跨站脚本”。这让ajax通话起作用了!希望能帮助别人。 – Mark 2012-02-17 15:12:40
很高兴帮助。请确保在jQuery调用之后将jQuery.support.cors重新设置为false以防止不需要的或意外的XSS。 – jbabey 2012-02-17 15:37:52
如果你把'的console.log()'或'警报()'点在哪里了'$获得()'是_that_执行? – nnnnnn 2012-02-17 14:17:03