开发者

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="sekar@example.com";
        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!


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="sekar@example.com";
        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'];
 ?>


Is it because data has to be a string?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜