vkGunasekaran
vkGunasekaran

Reputation: 6814

problem in using jquery ajax


i dont know what is actual problem in the below code, but it doesn't work as i expected.

<html>
<head>
<script type='text/javascript' src='jquery-1.4.2.min.js'></script>
<script type='text/javascript'>
$(document).ready(function(){ 
    $('#clickme').click(function(){
        var uid="[email protected]";
        var upass="sample";
        $.ajax({
            type : 'GET',
            url : 'http://www.example.com/test.php',
            data: {
                em : uid,
                pass : upass,
                action : 'check'
            },
            success : function(msg){
                alert(msg);
            },
            error : function(XMLHttpRequest, textStatus, errorThrown){alert(errorThrown);}
        });
    });
});
</script>
</head>
<body>
<input type='button' value='click' id='clickme' />
</body>

</html>

In that test.php i simply tried to echo "hello world" or echo $_GET['action'] But none of this worked i got only empty message? can some one help me in this issue?
Thanks!

Upvotes: 0

Views: 109

Answers (2)

key2
key2

Reputation: 428

There is no error in your code. But never pass your passwords using GET. I create two files test.html and test.php.

Code of test.html:
<!-- language: html-->
 <html>
 <head>
 <script type='text/javascript' src='js/jquery.js'></script>
 <script type='text/javascript'>
 $(document).ready(function(){ 
    $('#clickme').click(function(){
        var uid="[email protected]";
        var upass="sample";
        $.ajax({
            type : 'GET',
            url : 'test.php',
            data: {
                em : uid,
                pass : upass,
                action : 'check'
            },
            success : function(msg){
                alert(msg);
            },
            error : function(XMLHttpRequest, textStatus, errorThrown){alert(errorThrown);}
        });
    });
 });
 </script>
 </head>
 <body>
 <input type='button' value='click' id='clickme' />
 </body>

 </html>

code of test.php:
<!-- language: php -->
 <?php
   echo $_GET['action'];
 ?>

Upvotes: 2

472084
472084

Reputation: 17894

Is it because data has to be a string?

data: "em="+uid+"&pass="+upass="&action=check",

Upvotes: 1

Related Questions