Javascript post data order -


i've got bit of funny problem i'm sure others here find easy solve. need hash entire query string, include hash value in post data.

after trying few other ways, i'm trying javascript. somehow seems order in string pulled form hashed differs way pulled when submitted.

i'm excluding hidden element specific class build query string hashed, setting hidden element hash value before final submit.

any idea might doing wrong, or how ensure order of elements same both on building string , submit?

the relevant snippet:

var allformdat = document.getelementbyid("frmpayment").elements; var hashingstring =''; var hashval; (i=0;i<allformdat.length;i++) {     if (allformdat[i].classname!="nohash"){         hashingstring+=allformdat[i].name+'='+allformdat[i].value+'&';     } }  hashingstring.substring(0, hashingstring.length - 1); hashingstring += '[salt]';  hashval=sha1(hashingstring); frm.hashvalue.value=hashval;  document.getelementbyid('frmpayment').submit(); 

first of all, you're not uri-encoding components. should:

var field = allformdat[i]; hashingstring += encodeuricomponent(field.name) + '='                + encodeuricomponent(field.value) + '&'; 

substring not work in-place. you'll have reassign:

hashingstring = hashingstring.substring(0, hashingstring.length - 1); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -