Support the ongoing development of Laravel.io →
posted 10 years ago
Input
Last updated 1 year ago.
0

You can try the Input::json() command to fetch the json sent via post request.

Last updated 1 year ago.
0

itsaafrin said:

You can try the Input::json() command to fetch the json sent via post request.

UPDATE:

Thank you. I have tried to check if

  if (Request::ajax())

and it does detect that the jquery is communicating properly so the route to it is correctly. Only, it sends an empty array which is shown with var_dump so the issue is inside the JQUERY code, why it is not sending it content

You can see it working at: http://foundmynicehome.com/public/showhospitals just change the choice at the select list and the URL box address does show the change but the controller gets no values

Last updated 1 year ago.
0

For the post request I am seeing the Content-Length: 0. This could be the issue. Can you verify that the data is being sent from the Jquery to the controller.

Last updated 1 year ago.
0

itsaafrin said:

For the post request I am seeing the Content-Length: 0. This could be the issue. Can you verify that the data is being sent from the Jquery to the controller.

Yes, I am also seeing that, it does notice there was some Ajax communication because it confirms it with the If input::ajax() ..., yet, nothing is being sent Dont know why. When I sent it via a submit button it did get the value, but I dont want that because it takes to reload the page. How do you mean "can you verify that the data is sent from the Jquery to the controller"? we are seeing that it is not sending. I wonder whether there is an additional line of code needed in the Jquery to send that value.

UPDATE

I am suspecting there is something incorrect in the form, when I write:

    onchange="submit(this.value)"

because this sort of mimics a "submission" to the URL but it does not talk to the Jquery code, thus, jquery code gets nothing and sends nothing. So the thing would be how to pass that value from the form to the Jquery

The JQUERY "talks" to the controller whether I used the combobox or not, of course, as the pages loads the jquery snippet is executed, but it has nothing, so nothing is sent. When I use the selectbox, I would need the .change(function) otherwise the JQUERY would not notice anything. However, if I include that, it skips the second method of the controller, and reads a bunch of other calls like the twitter call, google apis takes long to load, really confusing.

Last updated 1 year ago.
0

I just rechecked your code and the ajax is working properly now without the page reload. I got the following reply but i did not get the alert.

(the jquery talked to me bool(true){})

Try the following code to check if you able to fetch the json posted, check this within the condition where you are returning the reply above.

$var =  Input::json() 
dd($var);

Kategori?? From Malaysia?

Last updated 1 year ago.
0

Hi

:) kategori, actually a guy from Malasya had once a code to work with the controler and it worked out of the box when I used it, so I did not want to even change the name of the variable less it would break :)

UPDATE

I got this using your interesting code:

 object(Symfony\Component\HttpFoundation\ParameterBag)#125 (1) {
    ["parameters":protected]=>
     array(0) {
   }
}

the array is null but not clear what the rest above means

In addition I have a series of checks that I added to know where I am at the controller. These are the checks

public function postespecialidades(){
      if (Request::ajax())

{

echo "the jquery talked to me ";

}

    if (Input::has('especialidades'))
   {
       echo "there is some content";
   }

elseif (Input::ajax('especialidades'))
{
 $hello = Input::ajax('especialidades');
 var_dump($hello);

return Response::json(Input::get('target'));
   
}
 else{
      echo "I DID NOT GET ANYTHING";
    }
 }

}

Last updated 1 year ago.
0

Here is a complete working code for you. I already fix and tested it. Replace and enjoy. Note the route and controller i created temporary. you can change the name as you wish.

From Malaysia but developing Spanish web app. you dahsyat la bro... ;)

HTML Code

  <select name="target" id = "target" class="form-control" onchange="(this.value)">                 
                                        <option value="1">Alergologia</option>  
                                        <option value="2">Anatomia patologica</option>  
                                        <option value="3">Angiologia</option>  
                                        <option value="4">Aparato digestivo</option>  
                                        <option value="5">Cardiologia</option>  
                                        <option value="6">Cirugia general</option>  
                                        <option value="7">Estomatologia</option>  
                                        <option value="8">Cirugia plastica</option>  
                                        <option value="9">Cirugia maxilofacial</option>  
                                        <option value="10">Dermatologia</option>  
                                        <option value="11">Ginecologia</option>  
                                        <option value="12">Oftalmologia</option>  
                                    </select>

Jquery

       <script>
            $(document).ready(function() {
                $("#target").change(function() {
                     //alert($('#target option:selected').val());
                    $.ajax({
                        type: 'POST',
                        url: 'http://localhost/tracer/public/test',
                        data: {'dataString': $('#target option:selected').val()},
                        cache: false,
                        success: function(data)
                        {
                            alert(data);
                        }
                    });

                });

   
            });

        </script>

Route

Route::get('/test', function()
{
	return View::make('test');
});

Route::post('/test', array('uses' => 'Authorized@test'));

Controller Code

    public function test() {
        if (Request::ajax()) {

            $data['input'] = Input::get('dataString');
            return $data['input'];
            
           
            
        }
    }
Last updated 1 year ago.
0

Thank you very much! I am going to study that in order to fully understand it

This is wonderful! what a relief! If you want I can include your name in the makers of the web.

So this is the solution and it is much more than that, it is someone who really helped me out. I had spent 8 hours stuck on this and I was completely at lost at where the issue could be.

Last updated 1 year ago.
0

writingcode said:

Thank you very much! I am going to study that in order to fully understand it

You are welcome, the issue was with your frontend jquery and naming convention that resulted in the data not being passed. You can mark it as solved ;)

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.