success block is not getting executed

success block is not getting executed

The website that I have worked on has a requirement to reload the page based on the city selected from the drop down. I have implemented the functionality but for some reason, the success block is not getting executed and due to this the page url is appended with '/undefined'. The issue pages of the web page is below

There is a different search section for mobile devices and the ids have been changed to not to conflict. Below is the script used.

<scriptype="text/javascript">
$(document).ready(function() {
function cityChange()
{
//alert("City change triggred");
var city = $('#CityId option:selected').val();
return city;
}
$('#CityId').change(function(e) {
//alert("In City change");
var city = cityChange();
var dataString = 'city=' + city;
var l = window.location;
var base_url = l.protocol + "//" + l.host + "/" + l.pathname.split('/')[1];
var newBase_url = l.protocol + "//" + l.host + "/" + l.pathname.split('/')[1];
var pathArray = l.pathname.split( '/' );
if(pathArray[1] == "city"){ //If block for city modules. This section is not used in Master
newBase_url += "/city/" + city;
for ( i = 2; i < pathArray.length - 1; i++ ) {// Initial count 2 for production 3 for localhost
newBase_url += "/" + pathArray[i];
}
}else if(pathArray[1] == "listing"){ //Else block for Listing modules
var listingPathArray = ($('div.breadcrumbs a:last').attr('href')).split('/'); //Ref: http://stackoverflow.com/questions/8647318/get-href-attribute-on-jquery
newBase_url += "/" + city;
for ( i = 2; i < listingPathArray.length; i++ ) {// Initial count 2 for production 3 for localhost
newBase_url += "/" + listingPathArray[i];
}
}else if(pathArray.length == 2){// Initial count 2 for production 3 for localhost
newBase_url = base_url;
}else{ //Else block for Categor & Segment modules. This section is not used in Master
newBase_url += "/" + city;
for ( i = 2; i < pathArray.length; i++ ) {// Initial count 2 for production 3 for localhost
newBase_url += "/" + pathArray[i];
}
}
$('#newurl').val(newBase_url);
var sesReq = base_url+"/setCitySess.php";
$.ajax({
type: "POST",
url: sesReq,
data: dataString,
dataType: 'json',
cache: false,
success: function(response) {
var newBase_url = $('#newurl').val();
window.location.href=newBase_url;
}
});
return false;
}); 
});
</script>