ajax调用返回网络错误>> 404

if(activePage.attr('id') === 'register_page') {
    $(document).on('click', '#submit', function() { // catch the form's submit event
        if($('#fname').val().length > 3 && $('#lname').val().length > 3 && $('#username').val().length > 4 && $('#email').val().length > 5 ){

            userHandler.username = $('#username').val();

            // Send data to server through the Ajax call
            //$.post( "http://127.0.0.1/projects/register2.php", $( "#register-user" ).serialize() );

            // action is functionality we want to call and outputJSON is our data
            $.ajax({
            url: 'http://127.0.0.1/projects/services/register.php',
            data: {action : 'registration', formData : $('#register-user').serialize()},
            type: 'post',                  
            async: true,
            contentType: "application/json; charset=utf-8",
            dataType: 'JSON ',
            beforeSend: function() {
                    // This callback function will trigger before data is sent
                    $.mobile.loading('show'); // show Ajax spinner
                },
                complete: function() {
                    // trigger on data sent/received complete   
                    $.mobile.loading('hide'); // hide Ajax spinner
                },
                success: function (result) {
                    // Check if registration successful
                    if(result.status == 'success') {
                        userHandler.status = result.status;
                        $.mobile.changePage("#categories");                        
                    } else if(result.status == 'failure'){
                         $("#register-error").text("System failure... please try again!").show().fadeOut(3000);
                    }
                    else if(result.status == 'taken'){
                        alert('Username or email is taken!');
                    }
                },
                error: function (xhr, status, error ) {
                    // This callback function will trigger on unsuccessful action               
                    //alert('Network error has occurred please try again!'); >> kanyagia hapa
                    $("#register-error").text(xhr.status+ "Network error... please check and try agin!").show().fadeOut(3000);
                }
            });   

The php file>> as shown below with Access headers works fine, without the access, the xdk emulator returns network error

                <?php
      header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PUT');
require './services/config.php';

if(!empty($_POST))
{
    $errors=0;
    if(empty($_POST['fname']) || empty($_POST['lname']) || empty($_POST['username'])
            || empty($_POST['email']) || empty($_POST['pword']))
    {
        $errors++;
        $error_msg="Please fill all the fields";
        $status =(true);
       echo '{"empty":'.json_encode($status).'}';
    }
    //pick all the data
    $fname=$_POST['fname'];
    $lname=$_POST['lname'];
    $usern=$_POST['username'];
    $email=$_POST['email'];
    $pass=$_POST['pword'];
    $role=$_POST['role'];

    //encrypt pw
    $encrypt_pw=  md5($pass);
    //check if errors are still 0 and check user existence
    if($errors==0)
    {
        $query="SELECT * FROM users WHERE username=:aa OR email=:bb";
        $query_params=array(
            ':aa'=>$usern,
            ':bb'=>$email
        );

        try{
            $stmt=$db->prepare($query);
            $result=$stmt->execute($query_params);
        } catch (Exception $ex) {
            $errors++;
            $error_msg="Server failure... please try again";
             $status =("0");
              echo '{"status":'.json_encode($status).'}';
        }
        $row=$stmt->fetch();
        if($row)
        {
           $errors++;
           $error_msg="Username or email already exists"; 
           $status =(true);
            echo '{"exists":'.json_encode($status).'}';
        }
        //if errors still 0
        if($errors==0)
        {
            $query="INSERT INTO users(fname, lname, username, email, password, role, created_at) VALUES(:aa, :bb, :cc, :dd, :ee,:ff, NOW())";
            $query_params=array(
                ':aa'=>$fname,
                ':bb'=>$lname,
                ':cc'=>$usern,
                ':dd'=>$email,
                ':ee'=>$encrypt_pw,
                ':ff'=>$role
            );

            try{
                $stmt=$db->prepare($query);
                $result=$stmt->execute($query_params);
            } catch (Exception $ex) {
                $errors++;
                $error_msg="Server failure... please try again";
                $status = array("status" => "failure");
                 echo json_encode($status);
            }

            if($errors==0)
            {
                //registration successful
                $success_msg="You registered";
                $status =(true);
                 echo '{"success":'.json_encode($status).'}';
            }
        }

    }

}
/*
some interface here..
*/
?>

404 means the URL you tried to reach wasn't found. I suspect, from a comment above your ajax url, that it should be http://127.0.0.1/projects/register2.php instead of http://127.0.0.1/projects/register.php.

A 404 error means the resource the call is trying to obtain does not exist, so you might want to check where that call is going and what it is trying to get back.

The call here is also going to a specific IP address, so I'm assuming you are testing this locally, but what you set there may not be running if it is returning a 404.