javascript如果然后加载ajax和输入计数



如何在这个"if语句中加载ajax "

if (code) {
drawLine(code.location.topLeftCorner, code.location.topRightCorner, "#FF3B58");
drawLine(code.location.topRightCorner, code.location.bottomRightCorner, "#FF3B58");
drawLine(code.location.bottomRightCorner, code.location.bottomLeftCorner, "#FF3B58");
drawLine(code.location.bottomLeftCorner, code.location.topLeftCorner, "#FF3B58");

// Then here i would like to call ajax and visit a url like this
$.ajax({
url: "save.php",
type: "POST",
data: {
type: 1,
name: name,
email: email                  
},
cache: false,
success: function(dataResult){
var dataResult = JSON.parse(dataResult);
if(dataResult.statusCode==200){

/// my code if success


}
else if(dataResult.statusCode==201){

///my code if failure.

}

}
});


} else {

我的其他问题是我如何检查javascript,如果输入有6个字符/数字输入,如果然后做同样的事情执行ajax,但在其他函数中,而不是在if语句中显示

var a = documentGetElementByid("mystringlength").length;

if (a == 6) {

. ajax({美元url:"process_six_figure.php"类型:"POST",数据:{},缓存:假的,成功:函数(dataResult) {//处理六位数的输入}),失败:函数(dataResult) {//在这里处理错误{);

});

总是尽量使你的代码有条理。

处理HTTP请求的正确方法如下:

function ajaxHTTP(url, dataPost, passAsParameter){
$.ajax({
type: "POST",
url: url,
data: dataPost,
dataType: "html",
success: function(data){
passAsParameter(data); //The function as passed as parameter
},
error: function(errMsg) {
//Network error
}
});
}
ajaxHTTP("https://example.net/my_server.lang", { field: "value" }, nameOfYourFunction);
function nameOfYourFunction(data){
//Make what you need (if and else)
}

相关内容

  • 没有找到相关文章

最新更新