0

Hello,

This is Laravel.

After inputting the profile_info I wonder why after checking the dd($here) the result remains the same. I expect it to change the same just like the value that I input.

setting.blade.php

<div class="setting-box profile-open">
    <form role="form" id="form_update_profile_info" method="post" action="{{action('AjaxController@postUpdateprofileInfo')}}">

        <div class="form-group">

            <div class="col-group">
                <textarea style="height: 150px;" class="form-control" id="profile_info" name="profile_info">{{ $user_setting->info_profile }}</textarea>

            </div>
        </div>

</form>
</div>

...

$(".setting-nav-save").click(function(e){
    e.preventDefault();
     var profile_info = $("#profile_info").val();

        $.ajax({
            type: "POST",
            url: '{{action("AjaxController@postUpdateprofileInfo")}}',
            dataType : "text",
            data : {
                 profile_info : profile_info,
            },
            success: function (response) {
                if (response!="error") {
                    $("div.profile").show();
                    $(".setting-nav-save").hide();
                    $(".setting-nav-cancel").hide();
                    $(".setting-nav-edit").show();
                    $("div.profile-open").hide();
                    response = response.replace('"',' ');
                    response = response.replace('"','');
                    response = response.replace("\u00A0", " ").replace(/[\r\n]+/g, "\n");
                    $("div.profile").html(response);

                    pesanOk("success update profile info");

                }else{
                    pesanErr("Oops try again");
                }
                }
            });
});     

AjaxController.php

public function postUpdateprofileInfo(Request $request)
    {

    $domain = $_SERVER['SERVER_NAME'];
    $user = User::where('domain', $domain)->first();

    $here = $request->input("profile_info");
    dd($here);

    if ($user) {
        $user_setting = Setting::where('user_id', $user->id)->first();
        $user_setting->info_profile = $request->input("profile_info");
        $act = $user_setting->save();
        if (!$act) {
            $message = "error";
        } else {

            $message = \Soulfy\Timeline::split_words($request->input("profile_info"), 2000, "...");
        }

        return response()->json($message);

    }
}
2
Contributors
1
Reply
21
Views
3 Months
Discussion Span
Last Post by pty
1

Just an idea. Rather than trying to do two things at once, first make one work then (when you're sure the first bit is correct) concentrate on the second.

If you can't answer the question of "which part is broken?" you're going to struggle.

Install httpie and then you can test your API simply from the command line:

http post localhost:4567 < payload.json

where payload.json contains

{
    "profile_info": "Hello world"
};

Once that works, then re-create that POST using jQuery's $.ajax(). The benefit of working this way is that if something doesn't work, you know exactly where the problem is.

Edited by pty

Votes + Comments
I fall down if I move both legs at the same time, unless I'm jumping?
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.