我有一个网站,当页面加载时,他应该打一个php文件。我正在使用下面的jquery ajax代码来传递php文件中的数据,这些数据给了我一些回应。但它在Mozilla中没有任何回报。但它的工作在IE和Chrome Brwser中非常完美。 任何人都可以帮助我吗?
<script>
window.onload = MyFunction;
var myString = "NO";
function MyFunction2() { // this function will be call on button click
// alert("button clicked");
myString = "Yes";
$("#myModal").removeClass("in");
$("#myModal").removeClass("fade");
$(".modal-backdrop").remove();
$("#myModal").hide();
$('#myfadeDiv').removeClass('in');
$('#myfadeDiv').removeClass('fade');
$('#myfadeDiv').removeClass('modal-backdrop');
MyFunction();
location.href = 'http://www.MyExampleWebsite.com/';
}
// function submitQuery() {
function MyFunction() {
$.ajax({
type: "POST",
data: ({ result: myString }),
url: "http://www.MyExampleWebsite.com/try.php",
success: function (html) {
if (html == " ") {
debugger;
$("#myModal").css("display", "block");
$('#myModal').addClass('in');
$('#myModal').addClass('fade');
$("#myModal").show();
$('#myfadeDiv').addClass('in');
$('#myfadeDiv').addClass('fade');
$('#myfadeDiv').addClass('modal-backdrop');
}
else {
debugger;
$("#myModal").removeClass("in");
$("#myModal").removeClass("fade");
$(".modal-backdrop").remove();
$("#myModal").hide();
$('#myfadeDiv').removeClass('in');
$('#myfadeDiv').removeClass('fade');
$('#myfadeDiv').removeClass('modal-backdrop');
}
}
});
return false;
}
function closewindow() {
if (confirm("Thank You. You May Close The Window.")) {
// close();
window.top.close();
window.parent.close();
var win = window.open("", "_self"); /* url = “” or “about:blank”; target=”_self” */
win.close();
window.close();
}
}
</script>
try.php
<?php header('Access-Control-Allow-Origin: *');
session_start();
$msg2 = $_POST['result'];
if($msg2=='Yes')
{
//session_start();
if( isset( $_SESSION['counter'] ) ) {
$_SESSION['counter'] += 1;
}else {
$_SESSION['counter'] = 0;
}
}
$msg = $_SESSION['counter'];
?>
<?php echo ( $msg ); ?>