开发者

jquery ajax problems with IE & Opera

The purpose of the ajax request below is simple really, just to send 2 variables from 127.0.0.1 to www.example.com/remoteScript.php file which is in remote server. So far it works perfectly fine in Safari, Firefox and Chrome (www.example.com/remoteScript.php file 开发者_C百科gets data from 127.0.0.1 and stores it into database).

But remoteScript.php doesn't seem to receive any data when I run that ajax in IE7, IE8, IE9 or Opera. Any suggestions? :)

This is part of my html (located in: 127.0.0.1)

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Statistics</title>


<script language="javascript" src="jquery-1.5.1.js"></script>
<script language="javascript" src="externalJS.js"></script>

<script type="text/javascript">
    initCI(); //function is located in externalJS.js
</script>
</head>

Part of my "externalJS.js" (located in: 127.0.0.1)

function initCI()
{   
    variable1 = "a string";
    variable2 = "a string";
    $(function(){
        $.ajax({
            url: "http://www.example.com/remoteScript.php?variable1="+variable1+"&variable2="+variable2,
            type: "GET",
        });
    });
}

remoteScript.php (located in: www.example.com)

<?php
    $variable1= $_GET["variable1"];
    $variable2= $_GET["variable2"];
    store variables to database...
?>


There may be a reason that you are not doing this, but I have done something similar using the $.post or $.get functions instead of the $.ajax function. This would look like the following for your example:

function initCI()
{   
    variable1 = "a string";
    variable2 = "a string";
    $.get('www.example.com/remoteScript.php',{ 'variable1':variable1,'variable2':variable2 });
}

You can also do something similar with the $.ajax function using the 'data' attribute instead of manually serializing your data into the URL.

The following links might be helpful in using the $ functions for ajax:

  • http://api.jquery.com/jQuery.ajax/
  • http://api.jquery.com/jQuery.get/

The $.ajax function itself has a lot of built-in functionality that might help you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜