我有一个js文件,可创建一个表单来收集客户的联系信息。提交表单后,它将向数据库发送一个url字符串。但是,字符串需要包含令牌和密码才能登录数据库。因此,我需要以某种方式将令牌和密码隐藏在php文件中,并在客户端点击“提交”时将其添加到字符串中。到目前为止,我已经能够使用.get或.ajax从php文件中获取数据,但是js文件已经使用了.ajax请求,我不确定如何将它们组合在一起。有任何想法吗?谢谢!
function initPopup() {
// open on load
if (xanadu_settings['show_popup'] == 'open') {
openXanadu();
}
// open on mouse out
else {
$('html > body').mouseleave(function() {
if (!popup_visible) {
openXanadu();
}
});
}
}
// This gets the login string i need to add to the form subit string below
var dataString = 'login';
$.ajax({
type: 'GET',
url: "login.php",
data: {data : dataString},
success: function(data) {
returnedvalue = data;
console.log(data);
}
});
$("#xanadu_wrapper form").validate({
rules: {
name: "required",
email: {
required: true,
email: true
}
},
messages: {
name: "Please specify your name",
email: {
required: "We need your email address to contact you",
email: "Your email address must be valid"
}
},
submitHandler: function(form, data) {
var report_url = "http://myLinkToTheAPI";
var submit_data = {
// token: $(form).find('input.token').val(),
// pass: $(form).find('input.pass').val(),
campaignId: $(form).find('input.campaignId').val(),
ipAddress: $(form).find('input#ipAddress').val(),
source: $(form).find('input.source').val(),
name: $(form).find('input.name').val(),
email: $(form).find('input.email').val(),
phone: $(form).find('input.phone').val(),
}
var form_submitted = false;
var submit_data = $(form).serialize();
$.ajax({
type: 'GET',
url: report_url,
data: submit_data,
complete: function() {
if ( ($(form).attr('action') != '') && (form_submitted == false) ) {
$(form)[0].submit();
form_submitted = true;
}
$(form).find('input, button').attr('disabled', '');
//Thank you! We will contact you shortly.
$(form).after('<p class="success-alert">' + xanadu_settings['success_message'] + '</p>');
$(form).next('.success-alert').fadeIn();
console.log(form);
console.log(form_submitted);
if (xanadu_settings['prevent_after_submission'] == 'true') {
setBlockCookie();
}
}
});
setTimeout(function(){
if ( ($(form).attr('action') != '') && (form_submitted == false) ) {
$(form)[0].submit();
form_submitted = true;
}
}, 500);
}
});
答案 0 :(得分:0)
您只是在AJAX调用中进行更新/插入吗?
当他们点击“提交”时,将序列化到该表单,将表单数据传递到接收页面,并处理服务器上的所有数据库交互。您永远不要在客户端上存储数据库信息。