Im using laravel
My ajax code in footer.blade
$(document).ready(function(){
$('.drpbtn').change(function (event) {
event.preventDefault();
$id=this.id;
$size=$('option:selected', this).val();
$.ajax({
url:"",
dataType:"json",
type:"post",
data:{
id:$id,
size:$size,
"_token": "",
},
success: function(result){
alert(result);
console.log(result);
}
});
});
});
My Route is Route::match(['get','post'],'/size_ajax','ajaxcontrol@size_ajax');
Im fetching row from my database using query builder with two condition, and my
My ajaxcontroller.blade
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Session;
use App\Http\Requests;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Response;
use App\product;
use App\prodattr;
use DB;
class ajaxcontrol extends Controller
{
public function size_ajax(Request $request){
$id = $request->id;
$size = $request->size;
$p_sku_sel = Prodattr::select('p_sku')->where([['p_id','=',$id],['size','=',$size]])->get();
$response = ['p_sku_sel' => $p_sku_sel];
return response()->json($response,200);
}
}
When I console the result in footer.blade it shows
{p_sku_sel: Array(1)}
p_sku_sel: [{…}]
__proto__: Object
But when I alert the result in footer.blade it shows
[Object] [Object]
Can anyone help me how to get the p_sku: value in ajax success function in footer.blade
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire