2016-09-30 77 views
1

我目前正在使用Ajax调用从JavaScript发送数据到PHP脚本的项目。我试图寻找Stackoverflow上的答案,但没有成功,因此我提出了一个问题。Ajax调用似乎在Firefox中失败

此代码在我的Chrome浏览器上正常工作,但在Firefox或Safari中尝试时失败。

$.ajax({ 
    method: "POST", 
    url: "index.php?option=com_lowbudgetrestvisual&task=sdc.connect&format=json", 
    cache: false, 
    data: { 
    data: data 
    }, 
    success: function(data, http, state) {}, 
    error: function(http, state, error) { 
    console.log("Response -> failed"); 
    console.log("http : " + http); 
    console.log("state: " + state); 
    console.log("error: " + error); 
    } 
}); 

编辑:每当我试图google chrome控制台日志,只是说:Response -> success。 当我尝试在Firefox中登录时,我收到以下文本。

Response -> failed http = [object Object] state = error error =

编辑2:我想提出一个form,然后将其提交给PHP script将其保存在database使用PHP。另一个ajax调用的形式是确保电子邮件以表格和管理员身份发送给用户。如何我确信这两个工作是由下面的JavaScript代码:

$('#sdc').on("click", function(e) { 

     e.preventDefault(); 

    {{ then some codes and the ajax call }} 

    }); 

    $('#sdc').on("click", function() { 
     $("#userForm").submit(); 
    }); 

编辑3:我试过console.log("http : " , http);,这是我在控制台中看到:

http = Object { 
     readyState: 0, 
     getResponseHeader: .ajax/v.getResponseHeader(), 
     getAllResponseHeaders: .ajax/v.getAllResponseHeaders(), 
     setRequestHeader: .ajax/v.setRequestHeader(), 
     overrideMimeType: .ajax/v.overrideMimeType(), 
     statusCode: .ajax/v.statusCode(), 
     abort: .ajax/v.abort(), 
     state: .Deferred/d.state(), 
     always: .Deferred/d.always(), 
     then: .Deferred/d.then(), 
     11 more… 
    } 
+2

有在控制台中的任何错误? –

+1

检查控制台是否存在请求中的错误 –

+2

你有没有检查过你的浏览器控制台,你在mozilla中遇到了什么类型的错误? –

回答

0

这段代码在Firefox中为我工作得很好。请检查Firefox浏览器版本和jQuery也。请检查服务器的PHP文件路径。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
 
<script> 
 
    $.ajax({ 
 
    method: "POST", 
 
    url: "test1.php", 
 
    cache: false, 
 
    data: { 
 
    data: 'test' 
 
    }, 
 
    success: function(data, http, state) {}, 
 
    error: function(http, state, error) { 
 
    console.log("Response -> failed"); 
 
    } 
 
}); 
 

 
</script>

+0

因此,我的Firefox可能会出现错误? – Hoffie

+0

请更新Firefox或在另一台机器上测试 – madankundu

+0

它适用于Chrome浏览器。但更新Firefox?这个ajax请求在旧版本的Firefox中不起作用吗? – Hoffie