Click here to Skip to main content
15,886,807 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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);
Posted
Updated 24-Nov-10 20:22pm
v2
Comments
Uwe Keim 25-Nov-10 1:39am    
Provide more information: Post the JavaScript error (if any) here,too.
amit_83 25-Nov-10 3:51am    
This is my whole java script code, it call on button click.
Whole code working in IE and Firefox also, but not working on
Safari.why?
why does alert message not come on success of Ajax call in IE and Firefox,
but method call successfully?

function SendMessage() {
var user = document.getElementById('<%=User.ClientID %>');
var val = user.value;
var nonrno = 1234;
var rno = 123;

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);
}

1 solution

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();
       }
    },


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() function instead of $.ajax() directly. $.post() is a wrapper for what you are trying to do with $.ajax() and may have defaults set that work in Safari.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900