Le but
Ce que j’ai essayé
.post()
avec une certaine influence du formulaire de soumission de jQuery AJAX . Les symptômes
Les théories
.submit()
pas preventDefault
au sein n’intercepte pas la soumission de formulaire traditionnelle HTML
We want to load the results within this div
JavaScript
var sortingmTextFields = function () { alert('sortingm fields'); }, checkForm = function (incoming_form) { alert('custom validation'); }; /* attach a submit handler to the form */ $('#form_edit_sensitivity').submit(function (event) { /* stop form from submitting normally */ event.preventDefault(); confirm('we got this far'); /* get some values from elements on the page: */ var $form = $(this), data = $form.serialize(), url = $form.attr('action'); /* Send the data using post */ var posting = $.post(url, data); /* Put the results in a div */ posting.done(function (data) { var content = $(data).find('#summary'); $('#result').empty().append(content); }); });
Pour paraphraser les mots immortels de la “Fille de la sororité dérangée” , je suis sur le sharepoint c-Punt mon ordinateur sur celui-ci.
Encore une fois, jsFiddle à http://jsfiddle.net/jhfrench/QjaTq/
var sortingmTextFields = function () { alert('sortingm fields'); }, checkForm = function (incoming_form) { alert('custom validation'); return true; // <-- NECESSARY BECAUSE YOU'RE RETURNING THIS IN "submit" EVENT }; $(document).ready(function() // DOM is ready... { /* attach a submit handler to the form */ $('#form_edit_sensitivity').submit(function (event) { /* stop form from submitting normally */ event.preventDefault(); confirm('we got this far'); /* get some values from elements on the page: */ var $form = $(this), data = $form.serialize(), url = $form.attr('action'); /* Send the data using post */ var posting = $.post(url, data, function(response) { /* Put the results in a div */ var content = $(response).find('#summary'); $('#result').empty().append(content); }); }); });
Je ne sais pas comment vous pouvez utiliser sortingmTextFields et checkForm (probablement globalement), mais déclarez-les dans $ (document) .ready () si vous le pouvez. Essayez toujours d'éviter les variables globales.
Vous devez envelopper votre js dans Ready Handler –
$(function(){ // write your js here });
Démo --->
http://jsfiddle.net/QjaTq/2/