0

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.

2
Contributors
10
Replies
11
Views
4 Years
Discussion Span
Last Post by romanromeo89
0

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.

0

Thanks for reply,

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

0

I get this from firebug:

POST register_check_0.php 200 OK 8ms
HeadersPostResponseHTML
success

This means that php file is ok ?

0

Indeed.

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

Edited by pritaeas

0

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

Edited by romanromeo89

0

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?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.