mardi 12 juillet 2016

Laravel 5.1 | VueJs request randomly returns a login request

Im working on a project using vuejs and laravel 5.1 but i have a major problem. When i add data to the database using this code through Vuejs it randomly returns with a get request to the login page and doesn't enter the data.

    this.$http.post('createAccount', this.account, function (data) {
        //disable the loader
        $('#loader').removeClass('active');

        //show the success message with the new user url
        var url = 'account=' + data;
        var astr ="<a href='" + url + "'>" + " Success! View The Account By Clicking Here " + "</a>";

        //Display sweet alert notification
        global.displaySuccess('User Created', astr);

        alert(astr);

        }).error(function(data, status, request) {
            global.displayError(status, 'Something went wrong!',
            'Please make sure that all the fields are filled out!');
    });

The above code works just fine about 3 times before it sends a request to go back to the login page as shown below.

Login request as well as create account request

And also when this happens sweet alert returns an extra 2 characters at the beginning of where the link should be. (Below Image)

Look at red circle

If you reference back to the code, note the alert(astr), this is just to see whats being returned by the data. Every time the login request is randomly added this alerts the HTML code for the login page.

enter image description here

Lastly just incase anyone is curious this is route that its being posted to along with the code that its accessing in the controller.

//routes.php
Route::group(['prefix' => 'profitloss', 'middleware' => 'perm'], function(){
    post('createAccount', 'AccountController@create');
});

//AccountController@create

 public function create(Request $request)
{

    $account = new Account();

    $account->account_username      = $request->input('account_username');
    $account->account_password      = $request->input('account_password');
    $account->email_address         = $request->input('email_address');
    $account->email_password        = $request->input('email_password');
    $account->notes                 = $request->input('notes');
    $account->gender                = $request->input('gender');
    $account->display_name          = $request->input('display_name');
    $account->first_name            = $request->input('first_name');
    $account->last_name             = $request->input('last_name');

    $account->save();

    //return the id of that account.
    return $account->id;

}

NOTE: I've had to disable CSRF because for some reason it keeps failing validation half the time and working the other half, However I don't think that this has anything to do with it.

Any help or information from anyone who has had a similar error to this would be greatly appreciated, thank you!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire