Actually, I've successfully pass data from my javascript to php and updated the database. However lately, I've been using laravel to develop my own website, and I've been trying to pass my data from javascript to laravel controller, the code looks like below
ProductController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use DB;
use App\Product;
class ProductController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$product = DB::select('select * from feedback');
return view('pages.addVisit');
// return view('products.index')
// ->with('product',$product);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('products.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$rating = new Product;
$rating->Name= $request->name;
$rating->save();
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
if(!empty($_POST['name']))
{
$output = "<script>console.log( 'this is name');</script>";
echo $output;
$obj = new ProductController();
$obj -> store($_POST['name']);
}
MyJavascript Here is my js
So, From what I've learn that the function store accept a post parameter, which is that store should catch my $_POST['name'](because i send to ProductController.php using ajax post)
the problem I'm facing now is that it seems the ProductController.php didnt receive data that I've pass from my js(i tried to echo some string inside the condition and it didn't show).
I've trying to figure it out for an hour,but it seems nothing wrong what am i doing wrong?