jQuery的验证插件 - 可以验证成功后不链功能
问题描述:
因此,所有我想要做的是,这部分代码:jQuery的验证插件 - 可以验证成功后不链功能
$(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();
});
}
});
}
});
});
如果你自己解决了这个问题,在后解答在答案中,而不是在答案中他质疑。 – Barmar