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
The Expected out is to redirect the outcome to a blade and appear as web-page not as a dev-tool response.