I'm trying to get some values from the url in the page. I'm not getting an array but a comma separated string. It works on the console but not on the site.
this is the url:
mysite.com/index.html?tags=tag2+tag1
This is my html header:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://www.parsecdn.com/js/parse-latest.js"></script>
<script type="text/javascript" src="home_recipes_js.php"></script>
This is the js code:
checkDocumentReady();
function checkDocumentReady() {
$(document).ready(function() {
var tagsString = getUrlVars()["tags"];
tagsParser(tagsString);
});
}
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
function tagsParser(tagsString) {
var rawTags = tagsString.split('+');
console.log('rawTags : ' + rawTags.length + ' ' + rawTags);
}
this is the console output:
tagsString: 2 tag2,tag1
What I'm I doing wrong?
rawTags[0]will give you first value in the array.