dpxf81245 2019-05-15 12:42
浏览 96

Laravel视图显示在chrome dev-tools上,而不是重定向到刀片

Good Day stackoverflow-Devs,

I'm working on a campaign project, where by you can create, edit & view your campaign before you publish it. I'm using MySQL and Firebase Real-time Database to store data. I wrote a JavaScript for-loop and inside there's a if statement with an ajax call to post the data to a laravel controller where by the controller just passes that data to a view.

I have tried using the following view methods:

 return view('view-campaign')->with('img',$img); //This one used to work perfectly

and:

 return redirect('view-campaign')->with('img',$img);

and lastly:

 return view('view-campaign', ['img',$img]);

Here is my Source Code:

Button

<td>
                                        <a onclick="viewCampaign('{{$item->id}}')" class="btn btn-success mb-2"
                                           data-toggle="tooltip" title="view campaign">
                                            <i class="fa fa-edit"></i> 
                                        </a>
                                  </td>

Javascript-Function

function viewCampaign(id){
        console.log(id);
        // Your web app's Firebase configuration
        var firebaseConfig = {
            apiKey: "apiKey",
            authDomain: "authDomain",
            databaseURL: "databaseURL",
            projectId: "projectId",
            storageBucket: "storageBucket",
            messagingSenderId: "messagingSenderId",
            appId: "appId"
        };
        // Initialize Firebase
        firebase.initializeApp(firebaseConfig);
        database = firebase.database();
        var ref = database.ref("CampaignCollection");

        //retrieve firebase stored data
        ref.on('value', function getData(data){
            var obj = data.val();
            var keys = Object.keys(obj);

            for(var i = 0; i < keys.length; i++) {
                var k = keys[i];
                var F_id = obj[k].id;
                var img = obj[k].Poster;
                var name = obj[k].Name;

                if(id == F_id){
                    $.ajax({
                        type: "POST",
                        url: "/viewCampaign",
                        data: {
                            'img': img,
                            "_token": "{{ csrf_token() }}",
                        },
                    })
                }
            }
        })
    }

view-campaign route

  Route::post('viewCampaign','CampaignController@viewCampaign');

view-campaign Controller

public function viewCampaign(){

        $img = $_POST['img'];

        return view('view-campaign')->with('img',$img);

    }

Response

enter image description here

The Expected out is to redirect the outcome to a blade and appear as web-page not as a dev-tool response.

  • 写回答

1条回答 默认 最新

  • dr637349 2019-05-15 12:58
    关注

    What you are doing is send an ajax request to a normal web route. It will return a web page. So that web page will be returned as the ajax response. You may need to submit the details as a form request.

    评论

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试