Saint Robson
Saint Robson

Reputation: 5525

.ajax() can't alert data sent from server

I have this HTML structure :

<html>
    <head>
    </head>
    <body>
        <script src="view/backoffice/assets/plugins/jquery/jquery-1.11.1.min.js" type="text/javascript"></script>
        <script>
            $(document).ready(function(){               
                $.ajax({
                    url: "../controller/ctrl.test.php",
                    success:function(data){
                        alert(data);
                    });
                });
            });
        </script>
    </body>
</html>

and ../controller/ctrl.test.php actually just to output some date and time, so to simplify, it just like this :

<?php
echo '2016/04/22 13:00:00'; 
?>

my question is, how to get 2016/04/22 13:00:00 as feedback when ajax is finished? I tried to json_encode('2016/04/22 13:00:00') but also didn't show up as alert.

I also read this tutorial : http://www.w3schools.com/jquery/ajax_ajax.asp, it can fetch txt file without problem, but why in my case, I can't get date from PHP file?

what did I missed here? thank you

Upvotes: 0

Views: 72

Answers (4)

JYoThI
JYoThI

Reputation: 12085

your success function should be like this

success:function(data){
 alert(data); }                  

not like this

success:function(data){
 alert(data); });

Upvotes: 0

Saint Robson
Saint Robson

Reputation: 5525

I found the problem :

the problem is here success:function(data){ alert(data); }); this should be success:function(data){ alert(data); }, without );

Upvotes: 0

maleeb
maleeb

Reputation: 920

.Check console for syntax error.

Here a working example:

<html>
    <head>
    </head>
    <body>
        <script   src="https://code.jquery.com/jquery-1.12.3.min.js"   integrity="sha256-aaODHAgvwQW1bFOGXMeX+pC4PZIPsvn2h1sArYOhgXQ="   crossorigin="anonymous"></script>
        <script>
            $(document).ready(function() {               
                $.ajax({
                    url: "http://jsonplaceholder.typicode.com/users",
                    success:function(data){
                        alert(data);
                    }
                });
            });
        </script>
    </body>
</html>

Upvotes: 1

kamlesh pandey
kamlesh pandey

Reputation: 185

@Robert check by using network capturing feature of browser if data is actually coming in the response body of the response or not and the format of the data in response .

Upvotes: 1

Related Questions