form segmentation value 'each' loop ajax request
I have a html form to get information from users. I segment this
information to launch from each segment an ajax request (the segmentation
is done following ">" characters). However, when I did not use 'each'
jquery function (so without segmentation) ajax works, but with each jquery
function ajax does not work at all and the loop does not work.
This is my javascript:
$(document).ready(function() {
$('#formu').on('submit', function() {
var sequence = $('#sequence').val().split(">"); // I segment here
$.each(sequence, function(k){ // for each segment I launch a
request with the segment as argument
if (sequence[k].length != 0){
alert(sequence[k]);
$.ajax({
url:'run.py',
type:$(this).attr('method'),
data: {'sequence':">"+sequence[k]}, // the segment
is given to python script
success: function(data){
$('#result').html(data);
}
});
} // enf if
//return false;
}); // end of each
}); // end of submit
}); // end of jquery
This is my html:
MyPage
<form method="post" id="formu" >
<textarea id="sequence" name="sequence" cols="80" rows="10"></textarea>
<br/>
<input type="submit" value="Submit">
</form>
<div id="result">
</div>
example of input:
>mysequence 1
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
>mysequence 2
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
>mysequence 3
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
No comments:
Post a Comment