0


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!

8
  • 2
    You should not pass passwords using GET. Secondly, are the pages on the same domain? Commented Jun 3, 2011 at 8:41
  • Can you post the test.php script? Commented Jun 3, 2011 at 8:43
  • I assume you're not actually using the URL: http://www.example.com/test.php Commented Jun 3, 2011 at 8:57
  • i think you are doing a cross-domain AJAX request which is not allowed due to security reasons. Commented Jun 3, 2011 at 9:09
  • @pimvdb No, i just created a test html pin client and accessed the test.php Commented Jun 3, 2011 at 9:31

2 Answers 2

2

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'];
 ?>
Sign up to request clarification or add additional context in comments.

2 Comments

@James Wiseman same thing i did, but it never worked, because this ajax code will be in client side [ firefox add on ], i tried it with full url but never worked... what should i do?
@Sekar: I only edited this post. I think you are confusing me with @user493376, who wrote the answer
1

Is it because data has to be a string?

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.