【问题标题】:Sending variables with ajax in laravel 5.4在 laravel 5.4 中使用 ajax 发送变量
【发布时间】:2017-08-11 00:31:40
【问题描述】:

这是我第一次做这种类型的发送,所以我希望你能帮助我,我在 laravel 5.4 中有一个网页,在一个页面上我有一个标签,显示我的数字,我想要那个数字出现在使用 ajax 的另一个页面上,但我不知道该怎么做。

这是我有标签的页面代码(我想发送):

<div class="col-md-3 col-sm-2 siga-cantidad">
    <label id="preciototalEmpresarialSiga">$25.000</label>
</div>

我希望该值出现在我的页面上的另一个标签中/测试我也有我的控制器和我的路线。

这是我的路线

Route::get('/prueba', 'PruebaController@index')->name('prueba');

这是我的控制器

class PruebaController extends Controller
{     
    public function index()
    {
        return view('pruebas');
    }

}

而且我不知道如何使用 ajax 向我发送我的标签数据。我希望我能说清楚,他们可以帮助我,在此先感谢大家。


是的,我想我不是很清楚......我在 laravel 5.4 中有这个网页,它在路径和控制器中

Route::get('/portal-de-calidad', 'PortalController@index')->name('portal');
class PortalController extends Controller
{
    public function index()
    {
        return view('portal');
    }
}

在这个 url(/portal-de-calidad) 我有这个代码

<div class="col-md-3 col-sm-2 siga-cantidad">
    <label id="preciototalEmpresarialSiga">$25.000</label>
</div>

我想要的是标签内的“$ 25.00”显示在另一个网页中..我知道使用ajax可以完成,但我不知道如何开始或将代码放在哪里.. . 在这里我把路线和我想要信息的页面的驱动程序明显显示在另一个标签上..

    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');
        }

    }

希望我已经说清楚了,能理解并帮助我...谢谢..!

【问题讨论】:

    标签: php ajax laravel-5.4


    【解决方案1】:

    目前尚不清楚您究竟想在这里实现什么,但使用 ajax 将数据发送到以下特定路由就足够了:

    AJAX 调用

    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
                }
              })
            }
    

    在你的控制器中

    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; 
    }
    

    【讨论】:

    • Disculpa creo q no me supe explicar biien ... en mi etiqueta label tengo un numero .... ahora quiero que ese numero se muestre en otra pagina ... espero esta vez me entiendas y puedas阿育达姆.... !! Gracias y disculpa por Competitionar recien ... la ruta del codigo que quiero enviar es esta Route::get('/portal', 'PortalController@index')->name('portal'); aqui esta el dato que quiero enviar a mi otra pagina q su ruta es Route::get('/prueba', 'PruebaController@index')->name('prueba');
    猜你喜欢
    • 1970-01-01
    • 2018-07-31
    • 2017-11-01
    • 2021-03-20
    • 2017-08-12
    • 1970-01-01
    • 2018-02-01
    • 2018-01-12
    • 1970-01-01
    相关资源
    最近更新 更多