Reputation: 1
This is my first time I'm doing this type of sending so I hope you can help me, I have a web page in laravel 5.4 which on a page I have a label that shows me a number and I want that number to appear On another page using ajax but I do not know how to do it.
This is the code of my page that I have the label (which I want to send):
<div class="col-md-3 col-sm-2 siga-cantidad">
<label id="preciototalEmpresarialSiga">$25.000</label>
</div>
I want that value to appear in another label on my page / tests that I also have my controller and my route.
This is my route
Route::get('/prueba', 'PruebaController@index')->name('prueba');
This is my controller
class PruebaController extends Controller
{
public function index()
{
return view('pruebas');
}
}
And I do not know how to do with ajax to send me that data of my label. I hope I could be clear and they can help me, in advance many thanks to all.
Yes, I think I was not very clear ... I have this web page in laravel 5.4, it is in the path and in the controller
Route::get('/portal-de-calidad', 'PortalController@index')->name('portal');
class PortalController extends Controller
{
public function index()
{
return view('portal');
}
}
In this url(/portal-de-calidad) I have this code
<div class="col-md-3 col-sm-2 siga-cantidad">
<label id="preciototalEmpresarialSiga">$25.000</label>
</div>
What I want is that the "$ 25.00" that is inside the label is displayed in another web page .. I understand that with ajax can be done but I do not know how to start or where to put the code ... Here I put the route and the driver of the page where I want the information appears obviously on another label ..
Route::get('/prueba', 'PruebaController@index')->name('prueba');
<label>"Here I want you to show me the information on the portal page"</label>
class PruebaController extends Controller
{
public function index()
{
return view('prueba');
}
}
I hope I have been clear and can understand and help me ... thanks ..!
Upvotes: 0
Views: 774
Reputation: 449
It is not clear what exactly you are trying to achieve here but for sending data using ajax to a specific route following should suffice :
AJAX Call
function postLabel()
{
var value = $('#preciototalEmpresarialSiga').text();
$.ajax({
url : "{{url('/prueba')}}",
type : "GET",
data : { 'price' : value },
success:function(data){//200 response comes here
//Do what you want to do with processed data
},
error:function(e){
//Error handling
}
})
}
And in your Controller
public function index()
{
if( !Input::has('price') )//Check if input exist
return response('Bad request', 400);
$price = Input::get('price');
//Also you should validate your data here
//Process data
return $price;
}
Upvotes: 1