First off all: I know nearly nothing about jquery (just "vanilla" javascript).
I have a simple form which sends a small text file and some parameters to the php-script which makes some changes into the file, sends it back (to the user's browser) as well as some feedback (about what was done to the file). Feedback is just a text string:
echo $feedback; // last line in my php-script
Well, it's working fine. The file-stuff part I mean. And I do get the feedback as well. But I would like to see it in the special div-box on the same page as my form is and for some reason browser keeps trasfering me to the php-script page. Here's the jquery script (I just put together from the different examples and answers in stackoverflow):
<body>
<form id="uploadSrt" enctype="multipart/form-data" method="post" action="http://myserver/script.php">
<input name="lyhikerida" type="text" maxlength="10" value="20"/>
<input id="fail" name="uploadFile" type="file"/>
</form>
<div id="kast"></div>
<script>
$('#fail').change(function(){
var frm = $('#uploadSrt');
frm.submit(function (ev) {
$.ajax({
type: frm.attr('method'),
url: frm.attr('action'),
data: frm.serialize(),
success: function(response){
$('#kast').html(response);
};
});
return false;
});
});
</script>
</body>
Can you tell me, what's wrong with the script? Or is it wrong idea?
EDIT: Sorry not to mention it, but the jquery script is already at the end of the body.
EDIT2: Added the whole 'body' part (except that 'http://myserver/script.php'). Event listener seems to be working (tested with lot of 'alerts'), buts the rest of the script... it's just like it's not there. :( And switching to 'return false;' didn't change a bit.