如何在firefox浏览器中修复ajax调用,但在chrome浏览器中可以正常工作

时间:2018-12-20 07:19:29

标签: java json ajax jsp firefox

以下是JavaScript,要调用ajax函数,$ ajax在firefox中不起作用,但在chrome中起作用。 ajax在firefox浏览器中未收到响应。

function ajaxAsyncRequest(){

            alert("ajaxAsyncRequest function");
            var tempValUrl = $(".urlVal").val();
            var url = tempValUrl + 'DepartmentUser/departmentUserTokenReceive';
            alert("url=="+url);

                $.ajax({
                        url : url,
                        method : 'GET',
                        contentType : "application/json",
                        dataType : "json",
                        success : function(response) {
                            alert(response);
                            var obj = response;
                            alert(obj);
                            alert("keyType" + obj.keyType);

                            if (obj.keyType == "sign") {
                                document.getElementById("signName").value = obj.name;
                                document.getElementById("certNumber").value = obj.serialNumber;
                                document.getElementById("signCa").value = obj.issuer;
                                document.getElementById("signExpiryDate").value = obj.tempDateTime;
                                document.getElementById("signPublicKey").value = obj.publicKey;
                            }

                            if (obj.keyType == "cipher") {
                                document.getElementById("cipherName").value = obj.name;
                                document.getElementById("cipherCertNumber").value = obj.serialNumber;
                                document.getElementById("cipherCa").value = obj.issuer;
                                document.getElementById("cipherExpiryDate").value = obj.tempDateTime;
                                document.getElementById("cipherPublicKey").value = obj.publicKey;
                            }

                        }

                    });
        }

1 个答案:

答案 0 :(得分:0)

您必须将event定义为事件处理程序的参数:-

event.preventDefault();