Placering af funktioner i ekstern fil
Jeg har flere scripts der ligner denne:
<script type="text/javascript">
$(document).ready(function() { // wait for the DOM to be ready
$('#personal_email').submit(function() { // bind function to submit event of form
$.ajax({
type: $(this).attr('method'), // get type of request from 'method'
url: $(this).attr('action'), // get url of request from 'action'
data: $(this).serialize(), // serialize the form's data
success: function(responseText) {
// if everything goes well, update the div with the response
$('#result').html(responseText);
}
});
return false; // important: prevent the form from submitting
});
});
</script>
Jeg har prøvet at lave en eksterne fil, men jeg kan ikke få den til at virke:
$(document).ready(function() { // wait for the DOM to be ready
$('#personal_email').submit(function() { // bind function to submit event of form
$.ajax({
type: $(this).attr('method'), // get type of request from 'method'
url: $(this).attr('action'), // get url of request from 'action'
data: $(this).serialize(), // serialize the form's data
success: function(responseText) {
// if everything goes well, update the div with the response
$('#result').html(responseText);
}
});
return false; // important: prevent the form from submitting
});
});
$(document).ready(function() { // wait for the DOM to be ready
$('#personal_email').submit(function() { // bind function to submit event of form
$.ajax({
type: $(this).attr('method'), // get type of request from 'method'
url: $(this).attr('action'), // get url of request from 'action'
data: $(this).serialize(), // serialize the form's data
success: function(responseText) {
// if everything goes well, update the div with the response
$('#result').html(responseText);
}
});
return false; // important: prevent the form from submitting
});
});
$(document).ready(function() { // wait for the DOM to be ready
$('#personal_email').submit(function() { // bind function to submit event of form
$.ajax({
type: $(this).attr('method'), // get type of request from 'method'
url: $(this).attr('action'), // get url of request from 'action'
data: $(this).serialize(), // serialize the form's data
success: function(responseText) {
// if everything goes well, update the div with the response
$('#result').html(responseText);
}
});
return false; // important: prevent the form from submitting
});
});
Jeg må gøre et eller andet forkert rent opbygningsmæssigt. Hvordan placerer jeg f.eks. 3 af den type scripts i en ekstern fil?
Vil det være en fordel at lave 3 eksterne filer og så lade den underside der benytter et script loade den eksterne fil, eller betyder det ingenting hastighedsmæssigt?
