Tutorial :How do I format the url: for a jQuery ajax() request in CakePHP so it won't add a question mark to the url?


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:


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


Here's the code:

$(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?


make url manually

url: "/countries/tariff/"+escape($(this).val())  


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

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


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

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »