Welcome Guest, Not a member yet? Register   Sign In
Ajax error in safari?
#1

[eluser]Unknown[/eluser]
Quite new to codeigniter and already a strange problem.
I have a simple jquery ajax call which works fine inFF, chrome and even IE6, but returns error in Safari (v4.05 on Mac at least)????
I have broken down the code to almost nothing to try to find the anvwer, but no clue.
You can try it on : http://www.moonwork.se/trickbaze , just clik the submit button to trigger ajax. I get 2 error messages from the script: 'error0', and just 'error'.
Anybody know what's wrong, specifically for Safari?

Code:

The controller

Code:
<?php
class Ajax_test extends Controller{

    function _construct()
    {
        parent::Controller();
    }

    function form()
    {
        echo "Ajax ok!";
    }
}
?>

The view
Code:
<?php

?>
<html lang="en">
<head>
<style type="text/css"><!--
@import "<?php echo base_url(); ?>css/original.css";
--></style>

[removed][removed]

[removed]
$('document').ready(function() {
     $("form").submit(function(e) {
            alert("Klick!");
             e.preventDefault();
             var stuff = $.ajax(
                                    {
                                        url: "<?php echo base_url(); ?>index.php/ajax_test/form",
                                        type: "GET", data:"amount=" + "1" ,
                                        success: function(data)
                                        {
                                            alert(data)
                                        },
                                        error: function (XMLHttpRequest, textStatus, errorThrown)
                                        {
                                            alert("error" + XMLHttpRequest.status);
                                            alert("error" + XMLHttpRequest.responseText);
                                        }
                                    }
                               )

     });
});
[removed]

<title>Test!!!!!!</title>
</head>
<body>
<div id="searchdiv">
&lt;form name="ajaxtestform" id="ajaxtestform" action="" method="POST" enctype="application/x-www-form-urlencoded"&gt;
    &lt;input type="text" name="message" value="" size="40" maxlength="40"  min="" max="" accept=""/&gt;
    &lt;input type="submit"/&gt;
    &lt;/form&gt;
</div>
&lt;/body&gt;
&lt;/html&gt;
#2

[eluser]pickupman[/eluser]
A little tweak in the js
Code:
$("form").submit(function(e) {
            alert("Klick!");
             e.preventDefault();
             var stuff = $.ajax(
                                    {
                                        url: "&lt;?php site_url('/ajax_test/form');?&gt;",
                                        type: "POST",
                                        data: $(this).serialize(),
                                        success: function(data)
                                        {
                                            alert(data)
                                        },
                                        error: function (XMLHttpRequest, textStatus, errorThrown)
                                        {
                                            alert("error" + XMLHttpRequest.status);
                                            alert("error" + XMLHttpRequest.responseText);
                                        }
                                    }
                               )

     });
#3

[eluser]Unknown[/eluser]
Pickupman, that really helped me. Actually changing to
Code:
"&lt;?php site_url(); ?&gt;index.php/ajax_test/form"
was enough.
Thank you!




Theme © iAndrew 2016 - Forum software by © MyBB