开发者

Pass client side js variable into server side jscript

How can I get the query string from the browser url using client side js and set it as a variable to use in some server side scripting?

Client side script:

var project = getQueryString("P");

function getQueryString(param) {
    var queryString = window.location.search.substring(1);
    splitQueryString = queryString.split("&");

    for (i=0; i<splitQueryString.length; i++) {
        query = splitQueryString[i].split("=");
        if (query[i] == param) {
        return query[1];
        }
    }

}

Server side script:

response.write ('<td><a href="/index.asp?P=' + project + ">' + ob开发者_高级运维j.BODY[i].NAME + '</a></td>');


On ASP I think you're looking for String(Request.queryString("P"))

You have to use the String constructor because the queryString method returns a collection.


I've used the jQuery plugin getUrlParam to do this in the past. Worked pretty well.

var project = $(document).getUrlParam("P");


You can't set any variable in the client side to be used in a server-side script without passing the value to the server via some HTTP request (possibly XHR). So maybe I am misunderstanding your question.

Server-side scripting is typically used to generate HTML that is sent to the client side, and the server-side script is therefore done executing before the client can do anything, not to mention the server is in a completely different memory space.

Server-side scripting could also receive data from the client side, but only by way of another HTTP request from the client, as mentioned above.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜