I am using the following to extract variables from the URL
$.urlParam = function(name){
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
return results[1] || 0;
}
This works great with numbers, but, when I try it on a string it stops at the letter A
Ajax call below
$.ajax({
url: apiURL,
dataType: 'json',
data: {page: page, user_name:$.urlParam('user')},
success: onLoadData
});
Example URL:
http://mypage.com/pages/gf_profile?user=DaveSmith&items=show
Firebug Inspector Shows (look at user_name variable)
GET http://mypage.com/wishAPIs/profileWLAllAPI.php?page=1&user_name=D 200 OK 253ms
Another Example URL:
http://mypage.com/pages/gf_profile?user=HelenMajor&items=show
Firebug Inspector Shows
GET http://mypage.com/wishAPIs/profileWLAllAPI.php?page=1&user_name=HelenM 200 OK 253ms
Example URL that is ok:
http://mypage.com/pages/gf_profile?user=MickBrown&items=show
Firebug Inspector Shows
GET http://mypage.com/wishAPIs/profileWLAllAPI.php?page=1&user_name=MickBrown 200 OK 202ms
This is very bizarre, any ideas?
Try changing the regex to
Demo: Fiddle