Welcome Guest, Not a member yet? Register   Sign In
Ajax doesnt pass get value ?
#1

[eluser]michal85[/eluser]
Hi there

I've got some problems with my new app and hopefully someone can help me.

http://www.testcms.grpx.pl/pl/advert/add

Whatever I choose from "Type" I always have the same result - empty value.

Advert controller
Code:
function getcat_by_type()
{
        $typeid = $this->input->get('id_type');
         echo "TYPE - ".$typeid;
            
  }
#2

[eluser]livewirerules[/eluser]
what is your ajax code?
#3

[eluser]michal85[/eluser]
Code:
$(document).ready(function()
    {
        $(".cat_type").change(function()
        {
            var type_id = $(this).val();
            $.ajax
            ({
                type: "GET",
                url: "http://www.testcms.grpx.pl/advert/getcat_by_type",
                data: {'id_type':type_id},
                cache: false,
                success: function(html)
                {
                    $(".category").html(html);
                },
              error: function(){      
                      alert('Błąd');
              }
            });
        });
    });
#4

[eluser]livewirerules[/eluser]
Try this and see

Code:
function getcat_by_type()
{
        $typeid = $this->input->post('id_type');
         echo "TYPE - ".$typeid;
            
  }



Code:
$(document).ready(function()
    {
        $(".cat_type").change(function()
        {
            var type_id = $(this).val();
            $.ajax
            ({
                type: "POST",
                url: "http://www.testcms.grpx.pl/advert/getcat_by_type",
                data: {id_type:type_id},
                cache: false,
                success: function(html)
                {
                    $(".category").html(html);
                },
              error: function(){      
                      alert('Błąd');
              }
            });
        });
    });
#5

[eluser]michal85[/eluser]
Doesn't work. It returns "Błąd".
#6

[eluser]livewirerules[/eluser]
what is in .cat_type?
#7

[eluser]michal85[/eluser]
Code:
<select name="typ" class="cat_type">
<option value="-">choose</option>
<option value="1">Kupię</option>
<option value="2">Sprzedam</option>
  </select>
#8

[eluser]TheFuzzy0ne[/eluser]
Step 1) Install Firefox.
Step 2) Install the Firebug extension.
Step 3) Profit!

Firebug is extremely useful for this kind of thing. You can monitor requests to the server, and see what's being sent and what's being returned.
#9

[eluser]michal85[/eluser]
Yeah, I know Firebug. Great tool. However I still cant figure out why my code isnt working.

Firebug says that typid=1 but

$this->input->get('typid')

is empty.

I dont understand it and I've tried many things in last hours but with no effect.

Thanks for any help.
#10

[eluser]TheFuzzy0ne[/eluser]
That's because you're posting your data via your AJAX request. You need to use $this->input->post('typid') to get the value. POST is a wiser choice for AJAX calls, since you don't have to worry about disallowed characters causing your app to throw a wobbler.

With Firebug, experiment by returning data to your AJAX request. Maybe you could try passing:

Code:
echo json_encode($_POST);

from your controller method. That should let you see what's in the post array.




Theme © iAndrew 2016 - Forum software by © MyBB