Personal tools
You are here: Home log javascript
Document Actions

javascript

2   2009-4-19 parse URL to get parameters

one source http://www.webdevelopmentcentral.net/2006/06/parsing-url-variables-with-javascript.html:

var searchString = document.location.search;  
// strip off the leading '?'
searchString = searchString.substring(1);
var nvPairs = searchString.split("&");
for (i = 0; i < nvPairs.length; i++)
{
   var nvPair = nvPairs[i].split("=");
   var name = nvPair[0];
   var value = nvPair[1];
}

http://www.netlobo.com/url_query_string_javascript.html is regex-based:

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

3   2009-7-3 evil eval

Something like eval("("+response+")") is very tantalizing when you have a json string and want to convert it into js data structure right away.

However, if the response happens to turn into something non js, like an error message which contains some js keywords or some other wacky stuff, it'll mess up the syntax of all of the code. You'll get strange errors like

missing ) parenthetical

while your code is solid js.

« November 2009 »
Su Mo Tu We Th Fr Sa
1234567
891011121314
15161718192021
22232425262728
2930
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: