jQuery 验证插件 - 验证成功后无法链接函数
jQuery Validation Plugin - can't chain function after successful validation
所以我想做的就是这部分代码:
$(document).ready(function () { //predaj formu i automatski crtaj graf
$('#myform').on('submit', function (e) {
e.preventDefault();
$.ajax({
type: 'post',
url: 'upit.php',
data: $('#myform').serialize(),
success: function () {
var dataPoints = [];
$.getJSON("rez.json", function(data) { //uzmi JSON za tocke grafa
$.each(data, function(key, value){
dataPoints.push({x: value[0], y: parseInt(value[1])});
});
var chart = new CanvasJS.Chart("chartContainer",{
zoomEnabled: true,
animationEnabled: false,
axisY: {
title: "Power received"
},
axisX: {
title: "Distance"
},
data: [{
type: "line",
dataPoints : dataPoints,
}]
});
chart.render();
});
$.ajax({ //vrati rezultat
url:"novi.json",
success:function(result){
$("#disabledInput").val(result);
}
});
}
});
});
});
执行
通过这部分代码验证成功提交后:
$(document).ready(function () {
$('#myform').validate({ // initialize the plugin
rules: {
n1: {
required: true,
email: true
},
n2: {
required: true,
minlength: 5
}
},
errorPlacement: function(error, element) {
error.appendTo('#nameError');
},
submitHandler: function (form) { // for demo
alert('valid form submitted'); // for demo
return false; // for demo
}
});
});
我只是不能正确地链接它,我知道这两个是分开的脚本,所以我需要它们以某种方式链接起来。谢谢!
我还需要将 ajax 提交(第一个代码)代码分开,因为我想用许多其他功能调用它(播放是添加一个滑块,所以我每次更改滑块等时都提交它...) 但我不确定如何
编辑:我做到了,这是答案
$(document).ready(function () {
$('#myform').validate({ // initialize the plugin
rules: {
n1: {
required: true,
},
n2: {
required: true,
}
},
errorPlacement: function(error, element) {
error.appendTo('#nameError');
},
submitHandler: function (form) {
$.ajax({
type: 'post',
url: 'upit.php',
data: $('#myform').serialize(),
success: function(){
var dataPoints = [];
$.getJSON("rez.json", function(data) { //uzmi JSON za tocke
grafa
$.each(data, function(key, value){
dataPoints.push({x: value[0], y: parseInt(value[1])});
});
var chart = new CanvasJS.Chart("chartContainer",{
zoomEnabled: true,
animationEnabled: false,
axisY: {
title: "Power received"
},
axisX: {
title: "Distance"
},
data: [{
type: "line",
dataPoints : dataPoints,
}]
});
chart.render();
});
}
});
}
});
});
我做到了,答案在这里
$(document).ready(function () {
$('#myform').validate({ // initialize the plugin
rules: {
n1: {
required: true,
},
n2: {
required: true,
}
},
errorPlacement: function(error, element) {
error.appendTo('#nameError');
},
submitHandler: function (form) {
$.ajax({
type: 'post',
url: 'upit.php',
data: $('#myform').serialize(),
success: function(){
var dataPoints = [];
$.getJSON("rez.json", function(data) { //uzmi JSON za tocke
grafa
$.each(data, function(key, value){
dataPoints.push({x: value[0], y: parseInt(value[1])});
});
var chart = new CanvasJS.Chart("chartContainer",{
zoomEnabled: true,
animationEnabled: false,
axisY: {
title: "Power received"
},
axisX: {
title: "Distance"
},
data: [{
type: "line",
dataPoints : dataPoints,
}]
});
chart.render();
});
}
});
}
});
});
所以我想做的就是这部分代码:
$(document).ready(function () { //predaj formu i automatski crtaj graf
$('#myform').on('submit', function (e) {
e.preventDefault();
$.ajax({
type: 'post',
url: 'upit.php',
data: $('#myform').serialize(),
success: function () {
var dataPoints = [];
$.getJSON("rez.json", function(data) { //uzmi JSON za tocke grafa
$.each(data, function(key, value){
dataPoints.push({x: value[0], y: parseInt(value[1])});
});
var chart = new CanvasJS.Chart("chartContainer",{
zoomEnabled: true,
animationEnabled: false,
axisY: {
title: "Power received"
},
axisX: {
title: "Distance"
},
data: [{
type: "line",
dataPoints : dataPoints,
}]
});
chart.render();
});
$.ajax({ //vrati rezultat
url:"novi.json",
success:function(result){
$("#disabledInput").val(result);
}
});
}
});
});
});
执行
通过这部分代码验证成功提交后:
$(document).ready(function () {
$('#myform').validate({ // initialize the plugin
rules: {
n1: {
required: true,
email: true
},
n2: {
required: true,
minlength: 5
}
},
errorPlacement: function(error, element) {
error.appendTo('#nameError');
},
submitHandler: function (form) { // for demo
alert('valid form submitted'); // for demo
return false; // for demo
}
});
});
我只是不能正确地链接它,我知道这两个是分开的脚本,所以我需要它们以某种方式链接起来。谢谢!
我还需要将 ajax 提交(第一个代码)代码分开,因为我想用许多其他功能调用它(播放是添加一个滑块,所以我每次更改滑块等时都提交它...) 但我不确定如何
编辑:我做到了,这是答案
$(document).ready(function () {
$('#myform').validate({ // initialize the plugin
rules: {
n1: {
required: true,
},
n2: {
required: true,
}
},
errorPlacement: function(error, element) {
error.appendTo('#nameError');
},
submitHandler: function (form) {
$.ajax({
type: 'post',
url: 'upit.php',
data: $('#myform').serialize(),
success: function(){
var dataPoints = [];
$.getJSON("rez.json", function(data) { //uzmi JSON za tocke
grafa
$.each(data, function(key, value){
dataPoints.push({x: value[0], y: parseInt(value[1])});
});
var chart = new CanvasJS.Chart("chartContainer",{
zoomEnabled: true,
animationEnabled: false,
axisY: {
title: "Power received"
},
axisX: {
title: "Distance"
},
data: [{
type: "line",
dataPoints : dataPoints,
}]
});
chart.render();
});
}
});
}
});
});
我做到了,答案在这里
$(document).ready(function () {
$('#myform').validate({ // initialize the plugin
rules: {
n1: {
required: true,
},
n2: {
required: true,
}
},
errorPlacement: function(error, element) {
error.appendTo('#nameError');
},
submitHandler: function (form) {
$.ajax({
type: 'post',
url: 'upit.php',
data: $('#myform').serialize(),
success: function(){
var dataPoints = [];
$.getJSON("rez.json", function(data) { //uzmi JSON za tocke
grafa
$.each(data, function(key, value){
dataPoints.push({x: value[0], y: parseInt(value[1])});
});
var chart = new CanvasJS.Chart("chartContainer",{
zoomEnabled: true,
animationEnabled: false,
axisY: {
title: "Power received"
},
axisX: {
title: "Distance"
},
data: [{
type: "line",
dataPoints : dataPoints,
}]
});
chart.render();
});
}
});
}
});
});