在javascript函数内调用JQuery HTTP GET请求
首先,我要说我对Javascript和JQuery是新手。我想要完成的是在HTML页面上有一个提交按钮,它将调用我的在javascript函数内调用JQuery HTTP GET请求,javascript,jquery,Javascript,Jquery,首先,我要说我对Javascript和JQuery是新手。我想要完成的是在HTML页面上有一个提交按钮,它将调用我的.js文件中的dbQuery函数,该函数将变量的值打印到屏幕上,然后将它们添加到MySQL数据库中 我需要使用JavaScript变量selectedVisibleValue,该变量是在我的第一个函数dbQuery中定义的。之所以要这样做,是因为我有四个下拉列表,其中三个是隐藏下拉列表,仅根据第一个非隐藏下拉列表显示,只有一个隐藏的下拉列表是可见的 我想在PHP页面formPage
.js
文件中的dbQuery
函数,该函数将变量的值打印到屏幕上,然后将它们添加到MySQL数据库中
我需要使用JavaScript变量selectedVisibleValue
,该变量是在我的第一个函数dbQuery
中定义的。之所以要这样做,是因为我有四个下拉列表,其中三个是隐藏下拉列表,仅根据第一个非隐藏下拉列表显示,只有一个隐藏的下拉列表是可见的
我想在PHP页面formPage
中使用这些变量来执行数据库功能。下面是我的代码。我想将testing1
函数添加到dbQuery
函数中
我尝试过将它复制并粘贴到dbQuery
函数中,但它不起作用。我不想使用下面代码中的selectedVisibleValue
。我只是想用一些伪变量做一些测试
var dbQuery = function(){
var description = document.getElementById("jobDescription").value;
var selectedEquip = document.getElementById("equipmentList");
var selectedEquip1 = selectedEquip.options[selectedEquip.selectedIndex].text;
var selectedVisibleValue = $(".unitDropDowns select:visible").val();
document.getElementById("descriptionSummary").innerHTML = "<h3>Description</h3>" + "<p>" + description + "</p>";
document.getElementById("equipmentRan").innerHTML = "<h3>Equipment Ran </h3>" + "<p>" + selectedEquip1 + "</p>" + "<h3>Unit Number</h3>" + "<p>" + selectedVisibleValue + "</p>";
document.getElementById("equipmentRan").style.display = "block";
document.getElementById("descriptionSummary").style.display = "block";
}
var testing1 = function() {
$.get(
"formPage.php",
{paramOne : 123, paramX : 'abc'},
function(data) {
document.getElementById("equipmentRan").innerHTML = ('page content: ' + data);
}
);
}
var dbQuery=function(){
var description=document.getElementById(“jobDescription”).value;
var selectedEquip=document.getElementById(“设备列表”);
var selectedEquip1=selectedEquip.options[selectedEquip.selectedIndex].text;
var selectedVisibleValue=$(“.unitDropDowns选择:可见”).val();
document.getElementById(“descriptionSummary”).innerHTML=“Description”+”“+Description+””;
document.getElementById(“设备运行”).innerHTML=“设备运行”+”“+selectedEquip1+”“+”单元号“+”“+selectedVisibleValue+””;
document.getElementById(“equipmentRan”).style.display=“block”;
document.getElementById(“descriptionSummary”).style.display=“block”;
}
var testing1=函数(){
美元(
“formPage.php”,
{paramOne:123,paramX:'abc'},
功能(数据){
document.getElementById(“equipmentRan”).innerHTML=(“页面内容:”+数据);
}
);
}
//缓存对静态元素的引用
变量jobDescription=$(“#jobDescription”)
,选择equip=$(“#设备列表”)
,descriptionSummary=$(“#descriptionSummary”)
,equipmentRan=$(“#equipmentRan”)
;
函数dbQuery(){
//收集参数
变量参数={
jobDescription:jobDescription.val(),
selectedEquip1:selectedEquip.val(),
selectedVisibleValue=$(“.unitDropDowns选择:可见”).val()
}
//显示摘要
descriptionSummary.html('Description'+Description+'').show();
equipmentRan.html('Equipment Ran'+selectedEquip1+'单元号'+selectedVisibleValue+'')。show();
//干杯
$.get('formPage.php',参数,函数(数据){
html('页面内容:'+数据);
}
}
//缓存对静态元素的引用
变量jobDescription=$(“#jobDescription”)
,选择equip=$(“#设备列表”)
,descriptionSummary=$(“#descriptionSummary”)
,equipmentRan=$(“#equipmentRan”)
;
函数dbQuery(){
//收集参数
变量参数={
jobDescription:jobDescription.val(),
selectedEquip1:selectedEquip.val(),
selectedVisibleValue=$(“.unitDropDowns选择:可见”).val()
}
//显示摘要
descriptionSummary.html('Description'+Description+'').show();
equipmentRan.html('Equipment Ran'+selectedEquip1+'单元号'+selectedVisibleValue+'')。show();
//干杯
$.get('formPage.php',参数,函数(数据){
html('页面内容:'+数据);
}
}
在函数之间传递变量可能对您的项目有用
HTML:
按我
JS
$(文档).ready(函数(){
//这是另一个Do More函数,在下一个变量函数之前定义。
//这是您的.get()请求。
功能doMore(目标){
//对于输入目标,添加较大字体的类样式。
$(target.css('font-size',30);
}
//主要功能。
var dbQuery=function(){
//在HTML页面上显示动态文本。
var extra=$('#theBox').html('动态文本结果');
//运行其他函数,同时…发送正在使用的私有变量。
多莫尔(额外);
};
//“提交”按钮。
$('button')。在('click',function()上{
//启动函数。
dbQuery();
});
});
在函数之间传递变量可能对您的项目有用
HTML:
按我
JS
$(文档).ready(函数(){
//这是另一个Do More函数,在下一个变量函数之前定义。
//这是您的.get()请求。
功能doMore(目标){
//对于输入目标,添加较大字体的类样式。
$(target.css('font-size',30);
}
//主要功能。
var dbQuery=function(){
//在HTML页面上显示动态文本。
var extra=$('#theBox').html('动态文本结果');
//运行其他函数,同时…发送正在使用的私有变量。
多莫尔(额外);
};
//“提交”按钮。
$('button')。在('click',function()上{
//启动函数。
dbQuery();
});
});
以下是工作代码:
function dbQuery() {
window.description = document.getElementById("jobDescription").value;
var selectedEquip = document.getElementById("equipmentList");
window.selectedEquip1 = selectedEquip.options[selectedEquip.selectedIndex].text;
window.selectedVisibleValue = $(".unitDropDowns select:visible").val();
testing1();
}
function testing1() {
$(document).ready(function() {
$.get(
"formPage.php",
{paramOne : window.selectedVisibleValue, paramX : window.description, paramY : window.selectedEquip1},
function(data) {
document.getElementById("equipmentRan").innerHTML = (data);
}
);
});
}
以下是工作代码:
function dbQuery() {
window.description = document.getElementById("jobDescription").value;
var selectedEquip = document.getElementById("equipmentList");
window.selectedEquip1 = selectedEquip.options[selectedEquip.selectedIndex].text;
window.selectedVisibleValue = $(".unitDropDowns select:visible").val();
testing1();
}
function testing1() {
$(document).ready(function() {
$.get(
"formPage.php",
{paramOne : window.selectedVisibleValue, paramX : window.description, paramY : window.selectedEquip1},
function(data) {
document.getElementById("equipmentRan").innerHTML = (data);
}
);
});
}
这里什么不起作用?我不认为它会执行
testing1
函数的代码,它会在dbQuery
函数中显示它应该显示的所有内容,但是testing1
函数中的值永远不会打印到屏幕上。如果我从单独的提交按钮调用testing1
函数,它将rks as