为什么我的以下代码在Safari中不起作用? [英] Why does my below code not work in Safari?

查看:71
本文介绍了为什么我的以下代码在Safari中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我的以下代码在Safari中不起作用?下面的代码没有调用我的page方法,但是它可以在IE和Firefox上运行.
该方法正在调用,但警报消息未在IE中的FF警报消息工作中显示.为什么?

Why does my below code not work in Safari? The below code does not call my page method, but it works on IE, as well as in Firefox.
The method is calling but alert message does not show in FF alert message work in IE. Why?

var options = {
  type: "POST",
  url: "Test.aspx/SendMessage",
  data: "{''toMailAddress'':''" + val + "'',''rno'':''" + rno+ "'', ''nonrno'':''" + nonrno+ "''}",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function (response) {
    var val1 = response.d;
    alert(val1);
    if (val1 == "1") {
      // Below code is used to close the window, if message has been sent to the user sucessfully.
      var windowObj = window.self;
      windowObj.opener = window.self;
      windowObj.close();
    }
  },
  error: function (result) {
    alert("Error in " + result);
  }
};
//Call the PageMethods
$.ajax(options);

推荐答案

.ajax(options);
.ajax(options);


警报未显示可能是由于您试图显示警报后立即关闭窗口的事实.试试:

The alert not showing up could be caused by the fact that you are closing the window right after trying to display the alert. Try:

success: function (response) {
       var val1 = response.d;
       alert(val1);
       if (val1 == "1") {
        
         //var windowObj = window.self;
         //windowObj.opener = window.self;
         //windowObj.close();
       }
    },



至于它在Safari中不起作用,我可能会看一下contentType选项,它可能是utf-8引起了悲伤.

另外,也许考虑使用jQuery的



As for it not working in Safari, I might look at the contentType option, it''s possible utf-8 is causing grief.

Also, maybe think about using jQuery''s


.post()函数代替
.post() function instead of


这篇关于为什么我的以下代码在Safari中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆