JQuery Ajax call often not working on Safari 6

后端 未结 5 1660
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-10 09:51

My Ajax call is really simple as below:

function ajax(reqUrl, params , callback) {
console.log(\"Request URL \"+reqUrl);
var cond;
cond = $.ajax({
    type:          


        
相关标签:
5条回答
  • 2020-12-10 10:15

    I also met this problem.

    When I moved all code into $(function() {}), it worked.

    After that, I found I had defined a variable named key, which caused the problem.

    Just rename it, all things will be running.

    0 讨论(0)
  • 2020-12-10 10:15

    Please Test below Code. it is working fine.

    $.ajax({
    type: "POST",
    url:'@Url.Action("getResult","Controller")', 
    data: "{userName :'" + userName  + "',password :'" + password + "' }",
    contentType: "application/json; charset=utf-8",
    dataType: "html",
    success: function (data) {
    alert("here" + data.toString());
    });
    
    0 讨论(0)
  • 2020-12-10 10:19

    This seems to be a Safari issue. In this post there is a suggestion to add a beforeSend to your ajax-request.

    In your case:

    cond = $.ajax({
        type: 'post',
        url: reqUrl,
        data: params,
        beforeSend: function (event, files, index, xhr, handler, callBack) {
             $.ajax({
                 async: false,
                 url: 'closeconnection.php' // add path
             });
        },
        error:function(){ alert("some error occurred") },
        success: callback
    });
    
    0 讨论(0)
  • 2020-12-10 10:28

    This is use for MVC application.

    $.ajax({
    type: "POST",
    url:'getResult', 
    data: "{userName :'" + userName  + "',password :'" + password + "' }",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
    alert("here" + data.toString());
    });
    

    For Asp.net Application :

    $.ajax({
    type: "POST",
    url:'getResult', 
    data: "{userName :'" + userName  + "',password :'" + password + "' }",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
    alert("here" + data.toString());
    });
    

    if u have still the issue than please post ur complete code here. i will test and reply soon

    0 讨论(0)
  • 2020-12-10 10:34

    Finally, I found error .. Safari doesn't reload my JavaScript files again even disable Cache. So I put all of my JS code into:

    $(document).ready(function(){
     // start load my js functions
     init();
    });
    

    to reload my JS files when my page was ready. Cheer !

    0 讨论(0)
提交回复
热议问题