[英]Laravel view shows on chrome dev-tools instead of redirecting to blade
Good Day stackoverflow-Devs, 美好的一天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.
我正在使用MySQL和Firebase实时数据库来存储数据。 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.
我写了一个JavaScript for循环,里面有一个带有ajax调用的if语句,用于将数据发布到laravel控制器,控制器将控制器传递给视图。
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: 这是我的源代码:
<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>
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() }}",
},
})
}
}
})
}
Route::post('viewCampaign','CampaignController@viewCampaign');
public function viewCampaign(){
$img = $_POST['img'];
return view('view-campaign')->with('img',$img);
}
The Expected out is to redirect the outcome to a blade and appear as web-page not as a dev-tool response. 预期结果是将结果重定向到刀片并显示为网页而不是开发工具响应。
What you are doing is send an ajax request to a normal web route. 您正在做的是向正常的Web路由发送ajax请求。 It will return a web page.
它将返回一个网页。 So that web page will be returned as the ajax response.
因此该网页将作为ajax响应返回。 You may need to submit the details as a form request.
您可能需要以表单请求的形式提交详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.