2013-01-31 37 views
0

我使用Malsup's JQuery Form plugin與Spring MVC做一些Ajax查找。在Internet Explorer中JQuery Form JSON響應數據NULL

我遇到了與IE(驚喜)的問題。

JavaScript代碼:

var options = { 
    type: "POST", 
    cache: false, 
    success: displayList, 
    error: errorList, 
    url: 'test.jsp', 
    dataType: 'json' 
}; 

$('form').ajaxSubmit(options); 

function displayPolicyList(responseText, statusText, xhr, $form) 
{ 
    alert(responseText); // Works in all browsers 
} 


function errorList(xhr, ajaxOptions, thrownError) 
{ 
    alert(xhr.responseText); // Fine in firefox etc, NULL in IE 
} 

Spring代碼:

@ResponseBody 
public ResponseEntity<Map<String, String>> erroResponse() 
{ 
    Map<String, String> error = new TreeMap<String, String>(); 

    error.put("error", message); 

    HttpHeaders responseHeaders = new HttpHeaders(); 
    responseHeaders.setContentType(MediaType.TEXT_PLAIN); 

    return new ResponseEntity<Map<String, String>>(error, responseHeaders, 
               HttpStatus.INTERNAL_SERVER_ERROR); 
} 

在所有成功的所有瀏覽器工作正常。我可以閱讀和解析JSON響應,沒有任何問題。當我在JSON響應中返回500與我的錯誤消息時出現問題。在firefox,chrome等等中,它都如預期的那樣工作,errorList可以解析JSON響應。

但在IE中JSON爲空。我可以在我收到相同的十字起源錯誤JQuery的表單插件看到(無法訪問響應文件:類型錯誤:訪問被拒絕 )這裏詳細:

Access is denied. on jquery.form.js in IE

不過,我不訪問跨因爲它是一個單一的應用程序。

在jQuery插件,似乎是問題的塊是:

function getDoc(frame) { 
     var doc = frame.contentWindow ? frame.contentWindow.document : frame.contentDocument ? frame.contentDocument : frame.document; 
     return doc; 
    } 

當我回到HttpStatus.CREATED從它工作正常的控制器,但服務器的任何故障事件導致了上述函數拋出異常。

任何想法?

+0

請問您提交的形式有哪些正在提交文件域? – JAAulde

+0

它的確如此。這一切都可以在Controller獲得成功響應的情況下運行。問題所在的地方是當我根據對提交的數據的一些內部驗證從控制器返回500時。 – user2028936

+0

您是否對「正常」響應進行了特殊處理,使得JSON在TEXTAREA中返回?當我用這個插件提交表單時,哪個表單有一個文件輸入並且來自IE,我必須將JSON響應包裝在TEXTAREA中,因爲IE需要僞阿賈克斯(通過iframe)。您需要在500響應中添加相同的特殊處理。 – JAAulde

回答