views:

421

answers:

4

I'm trying to call the 'tariff' action of my 'countries' controller using jQuery ajax() and pass it a country name in the following format:

/countries/tariff/countryname

however, with the following code ( set to GET ), it is calling this with the get '?' added:

/countries/tariff/?countryname

$(document).ready(function(){
    $('#CountriesIndexForm select').change(function(){   
     $.ajax({
      type: "GET",

      url: "/countries/tariff/",

      data: escape($(this).val()),

      success: function(html){

       $(this).parent().next('div').html(html);

      }
     });
    }); 
});

I understand its because the type: is set to GET, but is there a fix for this?

+6  A: 

make url manually

url: "/countries/tariff/"+escape($(this).val())
evilbloodydemon
DOH!!!!!!!!!!!!!!!!!
Pickledegg
by the way, thanks ;)
Pickledegg
I always make the urls manually. You know for sure how its going to work.
DMin
+2  A: 

You need to append that to the url parameters and leave out data, i.e.:

url: "/countries/tariff/" + $(this).val(),
karim79
+2  A: 

Pass the parameter directly in the url field instead of using data

$(document).ready(function(){    
   $('#CountriesIndexForm select').change(function(){                          
      $.ajax({                
          type: "GET",                
             url: "/countries/tariff/" + escape($(this).val()),                
             success: function(html){                        
                  $(this).parent().next('div').html(html);                
             }        
      });    
    }); 
});
ichiban
A: 

and if i want to send something secret like password to server? is there any other way?

dung
Ask another question and don't answer to ask questions. You never send private information using GET -- A better way to do this is using POST instead.
DMin