Hello, I'm trying to send a new user info (username & password) to a php file (register_check_0.php) using ajax with jquery so i can check if user already exists. I use the post request below:

$.post("register_check_0.php",
          {
            username: $("#username").val(),
            password: $("#password").val()
          },
          function(data,status){
            var result=data;
            if(result=="success"){
                counter+=1;
                $("#registration").load("register_1.php");
            }
          }
        );

This is my php file:

<?php
//require_once('testfile.php');

$username=$_POST['username'];
$password=$_POST['password'];

if($username == "user"){echo "success";}else{echo "fail";}

?>

The testfile.php is empty, my code as is now, works fine. If type user in my form the result to ajax post request is success, but when i include the testfile.php it does not work.

**All files are at the same directory

Thank you in advance.

Add:

ini_set('display_errors', 1);
error_reporting(E_ALL|E_STRICT);

before the include and tell us if you get any errors if you just open your php file in the browser.

Thanks for reply,

I added the above lines and i don't have errors when access php file from browser.

What happens when you include the testfile and debug your Javascript code?

I get this from firebug:

POST register_check_0.php 200 OK 8ms
HeadersPostResponseHTML
success

This means that php file is ok ?

Indeed.

If your testfile has a unicode file marker, then success will be prepended with it, and your if will always fail.

Sorry but i dont know what unicode file marker is.
All my files are encoded with utf-8

I get success.
I converted the testfile.php from utf-8 to ANSI, and it seems to work.
Is it possible to get other errors with that?

As long as you use a file without a byte order mark, it will work just fine.

Thank you very much about your help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.