I'm trying to implement some basic ajax functionality in website I'm creating. I'm using the Flask microframework and jQuery to do this. I have a lot of experience with python, what Flask is written in, but very little with javascript. This would be why I decided to use jQuery. ;) There is a nice example included with the Flask documentation which I didn't have any trouble getting working, but when I applied the method in the example to my code I started running into problems getting jQuery to correctly populate the query string. Essentially, it parses some of my form elements, but not all.
My HTML form looks like this:
<form action method="GET" class="span-11 inline">
<fieldset>
<div class='span-5'>
<label for="msat_size">Msat Size:</label>
</div>
<div class='span-5 last'>
<select id="msat_size" name="msat_size"><option value="mono">Mono</option><option value="di">Di</option><option value="tri">Tri</option></select>
</div>
<div class='span-5'>
<label for="msat_length">Msat Length:</label>
</div>
<div class='span-5 last'>
<input class="text" id="msat_length" maxlength="3" name="msat_length" size="3" style="width:48px" type="text" value="0" />
</div>
<div class='span-5'>
<label for="msat_perfect">Perfect Msats:</label>
</div>
<div class='span-5 last'>
<input id="msat_perfect" name="msat_perfect" type="checkbox" value="y" />
</div>
<div class='span-5'>
<label for="combine_loci">Combine Microsatellites:</label>
</div>
<div class='span-5 last'>
<input id="combine_loci" name="combine_loci" type="checkbox" value="y" />
</div>
<div class='span-5'>
<label for="design_primers">Design Primers:</label>
</div>
<div class='span-5 last'>
<input id="design_primers" name="design_primers" type="checkbox" value="y" />
</div>
<div class='span-5'>
<label for="tag_primers">Tag Primers:</label>
</div>
<div class='span-5 last'>
<select id="tag_primers" name="tag_primers"><option selected="selected" value="None">No Tag</option><option value="cag">CAG Tag</option><option value="m13">M13R Tag</option></select>
</div>
<div class='span-5 prepend-5 last'>
<button id="submit_msats" name="submit_msats" type="submit" value="submit_msats" class="button positive">
<img src="/static/css/plugins/buttons/icons/tick.png" alt=""/> Submit
</button>
</div>
</fieldset>
</form>
My javascript looks like this:
<script type=text/javascript>
$(function() {
$('.button').bind('click', function() {
$.getJSON('/query_result', {
msat_size: $('input[id="msat_size"]').val(),
msat_length: $('input[name="msat_length"]').val(),
msat_perfect: $('input[name="msat_perfect"]').val(),
combine_loci: $('input[name="combine_loci"]').val(),
design_primers: $('input[name="design_primers"]').val(),
tag_primers: $('input[name="tag_primers"]').val(),
}, function(data) {
$("#stat1").text(data.msat_size),
$("#stat2").text(data.msat_length);
});
return false;
});
});
</script>
But after I submit my query string looks like this:
/query_result?msat_length=0&msat_perfect=y&combine_loci=y&design_primers=y
I can get the 'msat_length' value to change properly, none of the others. If I change the .val() to .text() in 'msat_size' line in the javascript, the name will appear in the query string, but without a value
/query_result?msat_size=&msat_length=0&msat_perfect=y&combine_loci=y&design_primers=y
Any thoughts on how to fix this would be greatly appreciated. Thanks!