var querystring = window.location.search.substring(1);
trace("querystring '" + querystring + "'");
var urlParams = parseQueryString(querystring);
public function parseQueryString(qs:String):Map {
var a:Array<String> = qs.split('&');
var pl = ~/\+/g; // Regex for replacing addition symbol with a space
var b = new Map<String,String>();
for ( i in 0...a.length)
{
var p=a[i].split('=');
var k:String =p[0];
if (p.length == 1){
trace("p " + k + "== *Blank*" );
b.set(k, "");
} else{
var v:String =StringTools.urlDecode(pl.split(p[1]).join(" "));
trace("p " + k + "==" +v );
b.set(k, v);
}
}
return b;
}
--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.
Am 06.10.2014 05:05, schrieb TroyWorks:
Reading there:Cool thanks for pointing that out. Pity it's not documented with other keyterms like "query string" that are commonly used to find it.
On Saturday, October 4, 2014 9:07:50 PM UTC-7, Pier Bover wrote:
Returns the current page GET and POST parameters (only GET parameters for Javascript)
I wonder if the class is not meant to be used for server side js as well?
Best,Juraj
The haxe.web.Request class object is global. Its API is fundamentally coupled with the assumption that only one request exists in all of your current context. That does not hold in node.
In node, you have instances of `IncomingMessage` that represent each request - see here: http://nodejs.org/api/http.html#http_http_incomingmessage
Similarly, you also cannot simply respond by `Sys.print`, because it is no clear which of the (con)currently processed requests you are responding to.
So yes, you could have a similar API, but there is not really a simple way to define it solely on global (class) objects.
Does that answer the question?
package url;
class UrlProperties {
private static var map:Map<String, String>;
public static function getProperty(queryId:String):String {
if (map == null) {
map = parseQueryMap(getQueryString());
}
return map.get(queryId);
}
private static function getQueryString():String {
return untyped __js__("window.location.search");
}
private static function parseQueryMap(qs:String):Map<String, String> {
var splitArray:Array<String> = qs.split('&');
var regexPlus = ~/\+/g; // Regex for replacing addition symbol with a space
var resultMap = new Map<String,String>();
for (i in 0...splitArray.length) {
var splitByEqual = splitArray[i].split('=');
var key:String = splitByEqual[0];
if (splitByEqual.length == 1) {
// ..&a=&b.. (right side blank)
resultMap.set(key, "");
} else {
var value:String = StringTools.urlDecode(regexPlus.split(splitByEqual[1]).join(" "));
resultMap.set(key, value);
}
}
return resultMap;
}
}