r/jquery • u/[deleted] • Apr 21 '15
.load querystring oddness...
So I have, a checkbox: <input id="Option-Projects1" type="checkbox" data-sourcesystem="Projects1" data-propertycode="1Lon01" data-property="600900">
and some js (JQ): $('input:checkbox').change(function () { var propertyCode = $(this).attr('data-propertycode'); var sourceSystem = $(this).attr('data-sourcesystem'); var property = $(this).attr('data-property'); var target = $('#selectResponse'); var selected = $(this).attr('checked'); if(selected == 'undefined') { selected ="notset"; } var string = 'SelectSourceSystemSelection.asp?SourceSystem=' + sourceSystem + '&propertycode='+ propertyCode + '&propertyname='+ property + '&selected='+ selected; target.load(string); });
where it says target.load, if I change this to alert(string); I get the correct string, however, when I view a network trace for the .load i'm seeing this:
Key Value Request GET /SelectSourceSystemSelection.asp?SourceSystem=Projects1&propertycode=1Lon01&propertyname=600900&_=1429612593048 HTTP/1.1
the last part of the string should read &selected=checked (or notset) but i'm getting :
&_=1429612593048
confuzzled!
1
u/BurkDiggler Apr 21 '15 edited Apr 21 '15
(Didn't see you posted this twice but I'll leave this here again anyway)
I'm not sure if this is causing your problem but I noticed a few issues with your code related to how you're setting the selected variable and this might be causing issues when creating the request.
First: $(this).attr('checked') won't actually give you the correct value for whether or not the checkbox is checked. Checked is a property and not an attribute so to get the value you should use $(this).is(':checked').
Second: Your if statement will always be false because you're comparing an object reference to a string. To check if something is undefined the if statement should be: if (typeof(selected) == 'undefined').
1
u/Malfuncti0n Apr 21 '15
Try using a JSFiddle or at least formatting your code for readability.
Some improvements:
http://jsfiddle.net/sjh91wf8/1/
Notice how I've changed the Selected variable to true/false which makes for easier code, and should be easy to use in your ASP.
As for your original question, there is not a great way to test this and I don't have any clue as why it changes to 'underscore'.
What does ASP return if you ask for
Request.QueryString("selected")