Simple jQuery post not working on Internet Explorer 9 (access denied)

I programmed a validator with JQuery and PHP that works in all browsers except Internet Explorer 9. I get the error message "SCRIPT5: Access denied".

jQuery code

$('#contact-send').click(function(){
  $.post('functions/db-contact.php',{
    contact_name: $('#contact-name').val(),
    contact_email: $('#contact-email').val(),
    contact_subject: $('#contact-subject').val(),
    contact_message: $('#contact-message').val()
  },
  function(x){
    console.log(x);
  }
});

And this is the response (x):

<?xml version="1.0"?>
<response>
  <mail>
    <name>1</name>
    <email>1</email>
    <subject>1</subject>
    <message>1</message>
    <status>notok</status>
  </mail>
</response> 
SCRIPT5: Access denied

EDIT: I really have no idea what can be the error. I added the DB contact file. @Brad :)

<?php
include 'db_login.php';

$name = mysql_escape_string($_POST['contact_name']);
$email = mysql_escape_string($_POST['contact_email']);
$subject = mysql_escape_string($_POST['contact_subject']);
$message = mysql_escape_string($_POST['contact_message']);

echo "<?xml version=\"1.0\"?>\n";
echo "<response>\n";
echo "\t<mail>\n";

$i = 0;
if($name == 'type your name' or $name == '' or strlen(trim($name)) == 0){
  echo "\t\t<name>1</name>\n";
  $i = 1;
}

if($email == 'type your email address' or $email == '' or strlen(trim($email)) == 0){
  echo "\t\t<email>1</email>\n";
  $i = 1;
}

if($subject == 'type subject' or $subject == '' or strlen(trim($subject)) == 0){
  echo "\t\t<subject>1</subject>\n";
  $i = 1;
}

if($message == 'type your message on us' 
  or $message == '' or strlen(trim($message)) == 0){
    echo "\t\t<message>1</message>\n";
    $i = 1;
}

if($i == 1){
  echo "\t\t<status>notok</status>\n";
  echo "\t</mail>\n";
  echo "</response>";
  return false;
}

$sql = "INSERT INTO `d013f578`.`mail` (`id`, `name`, `email`, `subject`, `message`)
       VALUES (NULL, '".$name."', '".$email."', '".$subject."', '".$message."');";
$query = mysql_query($sql) or die;
echo "\t\t<status>ok</status>\n";
echo "\t</mail>\n";
echo "</response>";
?>

Unfortunately I have not found any usable tip on the internet.

Answers


I found the solution! First you have to change the JQuery code. You have to use xdr requests for Internet Explorer. Here (http://stackoverflow.com/questions/5087549/access-denied-to-jquery-script-on-ie) you find more Informations about the JQuery code side. Thanks Stackoverflow awsome Community! :)

            $('#contact-send').click(function(){
                if($.browser.msie && window.XDomainRequest) {
                    // Use Microsoft XDR
                    var xdr = new XDomainRequest();
                    xdr.open("POST", "functions/db-contact-xdr.php");
                    xdr.send("&contact_name="+$('#contact-name').val()+"&contact_email="+$('#contact-email').val()+"&contact_subject="+$('#contact-subject').val()+"&contact_message="+$('#contact-message').val()+""); 
                    xdr.onload = function () {
                        var dom = new ActiveXObject("Microsoft.XMLDOM");
                        dom.async = false;
                        dom.loadXML(xdr.responseText);
                        $("mail",xdr.responseText).each(function(id) {
                            var mail = $("mail",xdr.responseText).get(id);
                            }
                        });
                    };
                }else{
                    $.post('functions/db-contact.php',{
                        contact_name: $('#contact-name').val(), 
                        contact_email: $('#contact-email').val(),
                        contact_subject: $('#contact-subject').val(),
                        contact_message: $('#contact-message').val()
                    },function(x){
                        $("mail",x).each(function(id) {
                            var mail = $("mail",x).get(id);
                            }
                        });
                    });
                }
            });

Even the PHP code I had to change to the data sent to the xdr request to use as POST variables, I used the PHP code taken from this page: http://saltybeagle.com/2009/09/cross-origin-resource- sharing demo.


Need Your Help

Best way to transfer data from View to complex controls

c# wpf xaml mvvm

I am building a control heavy application in wpf and I am trying use the best solution for various views (in terms of maintainability, scalability, etc).

ScriptManager loads multiple java scripts in asp.net ? i need them to be all in one as per YSlow guidelines

asp.net ajax

As per Yahoo's guidelines for performance of web sites , javascripts should be combined in one to avoid extra http request , as i saw in YSlow asp.net loads 3 to 4 scripts one for MicrosoftAjax.js...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.