Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This question already has an answer here:

My variables:

var strArgsString = "?Category=Customer&Year=2014";
var intModuleNo = "2";
var strOrigDashName = "Invoices"

My AJAX Post:

    var jqxhr = $.post("includes/saveParameters.asp?dname="+strOrigDashName+"&mod="+intModuleNo+"&args='"+strArgsString+"'", function() {
    alert("success");
})
.fail(function() {
    alert("error");
});

It returns a fail because the "args" value is treated as a continuation of the full query string. Im sure there will be many ways to do this but how can i get "?Category=Customer&Year=2014" treated as a string on my .asp file?

At the moment I have these

strDashboardName = Request.QueryString("dname")
intModuleNumber = Request.QueryString("mod")
strParamsArgString = Request.QueryString("args")

Any solution appreciated, but preferance given to the most efficient, thanks.

share|improve this question

marked as duplicate by Teemu, Shadow Wizard Jan 31 at 0:08

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Yes, use encodeURIComponent(); and then QueryString will automatically decode it. –  Spokey Jan 30 at 14:50

1 Answer 1

up vote 1 down vote accepted

I think you want to encode the args string so it can be represented as data, and not a literal continuation of the querystring.

var strArgsString = encodeURIComponent("?Category=Customer&Year=2014");
var intModuleNo = "2";
var strOrigDashName = "Invoices"

There are two additional options for encoding. encodeURI and escape. Please see Best practice: escape, or encodeURI / encodeURIComponent for further information.

share|improve this answer
    
encodeURIComponent got the desired result thanks. Sometimes you cant search for something when you dont know the solution. –  user29660 Jan 30 at 15:10
    
I'm sorry if I sounded like I meant you should have found the best practice prior to asking. That is NOT what I meant. I meant if you were curious about the differences that you could find the information there. I'm very familiar with the problem of search terms. =) –  Skerkles Jan 30 at 20:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.