2012-02-17 124 views
1

我在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上工作的祕密嗎?

+0

如果你把'的console.log()'或'警報()'點在哪裏了'$獲得()'是_that_執行? – nnnnnn 2012-02-17 14:17:03

回答

2

嘗試使用$ .ajax而不是$ .get,這樣您可以添加一個錯誤回調並查看爲什麼ajax調用失敗。

http://net.tutsplus.com/tutorials/javascript-ajax/5-ways-to-make-ajax-calls-with-jquery/ (見最後...在最後一節)

+1

謝謝 - 我添加了「.error(function(jqXHR,textStatus,errorThrown){alert(」Error:「+ errorThrown);})」改爲我的$ .get(真的是同一件事)並且出現「no transport」錯誤。谷歌搜索稱這涉及到跨域問題。然後,我添加了這一行來強制IE允許這樣做:「jQuery.support.cors = true; //強制跨站腳本」。這讓ajax通話起作用了!希望能幫助別人。 – Mark 2012-02-17 15:12:40

+0

很高興幫助。請確保在jQuery調用之後將jQuery.support.cors重新設置爲false以防止不需要的或意外的XSS。 – jbabey 2012-02-17 15:37:52