[英]How to make html form to submit to X page first wait for a while and submit to another Y page because Y page needs processed data of X page
// How do I make this javascript to submit to y.php first and wait a while until it is processed and submit to x.php //我如何使此javascript首先提交y.php并等待一段时间,直到处理完毕并提交给x.php
function validatedaily()
{
form=document.getElementById('myform');
form.action='y.php';
form.submit();
form.action='x.php';
form.submit();
}
try with this: 试试这个:
on jQuery 在jQuery上
You can use
$.ajax()
asjQuery.ajax()
. 您可以将$.ajax()
用作jQuery.ajax()
。 Learn about this API here 在此处了解有关此API的信息
$.ajax({
url : 'x.php',
type : 'get',
dataType: 'json'
success : function(xResponse){
$.ajax({
url : 'y.php',
type : 'get',
dataType: 'json'
success : function(yResponse){
}
});
}
});
on Angular: 在Angular上:
You can use
$http.get()
,$http.post
,$http.put()
, etc. Learn about this API here 您可以使用$http.get()
,$http.post
,$http.put()
等。 在此处了解此API
$http({
method : 'GET',
url : 'x.php'
}).then(function(xResponse){
// use xResponse.data to get response data
$http({
method : 'GET',
url : 'y.php'
}).then(function(yResponse){
// use yResponse.data to get response data
})
})
"Simple" XHR(pure javascript): “简单” XHR(纯javascript):
This method work on IE6+ and all Chrome, Chromium, Firefox and Safari versions. 此方法适用于IE6 +以及所有Chrome,Chromium,Firefox和Safari版本。 Learn about XMLHttpRequest API, MSXML2.XmlHttp.xx API and Microsoft.XmlHttp 了解XMLHttpRequest API, MSXML2.XmlHttp.xx API和Microsoft.XmlHttp
var ajax = {};
// prepare xhr api
ajax.x = function () {
var xhr;
if (typeof XMLHttpRequest !== 'undefined') return new XMLHttpRequest();
// API's
var versions = [
"MSXML2.XmlHttp.6.0",
"MSXML2.XmlHttp.5.0",
"MSXML2.XmlHttp.4.0",
"MSXML2.XmlHttp.3.0",
"MSXML2.XmlHttp.2.0",
"Microsoft.XmlHttp"
];
for (var i = 0; i < versions.length; i++) {
try {
xhr = new ActiveXObject(versions[i]);
break;
} catch (e) {
}
}
return xhr;
};
// function to send
ajax.send = function (url, callback, method, data, async) {
if (async === undefined) async = true;
var xhr = ajax.x();
xhr.open(method, url, async);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) callback(xhr.responseText)
};
if (method == 'POST') xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.send(data)
};
// you can use like this
ajax.send('x.php', function(xResponse) {
// console.log( xResponse );
ajax.send('y.php', function (yResponse) {
// console.log( yResponse )
}, 'GET')
}, 'GET')
You can try this 你可以试试这个
function validatedaily()
{
form=document.getElementById('myform');
form.action='y.php';
if(form.submit()){
form.action='x.php';
form.submit();
}
}
also try using ajax 也尝试使用ajax
$.ajax({url: "x.php", async:false, success: function(result){ another(result); }}); function another(result){ $.ajax({url: "y.php",success: function(result){ console.log(result); }}); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.