开发者

problem in using jquery ajax

开发者 https://www.devze.com 2023-03-09 23:49 出处:网络
i dont know what is actual problem in the below code, but it doesn\'t work as i expected. <html>

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

精彩评论

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