我的jquery不会在文档准备好的情况下运行我的java脚本函数。
cont += "<script>";
cont += "$(document).ready(function() {Puma.getReasonForBTI()});";
cont += "</script>";
JS功能
Puma.getReasonForBTI = function() {
var reason = document.getElementById("reasonId").value;
var msql = "SELECT Pid FROM tPid WHERE Reason = 'reason'";
sql = "action=getReasonForBTI&sql=" + encodeURIComponent(msql);
objAjaxAd.main_flag = "getReasonForBTI";
objAjaxAd.SendQuery(sql);
}
任何帮助都将不胜感激。
答案 0 :(得分:2)
为什么不直接将DocReady添加到JS?
Puma.getReasonForBTI = function() {
var reason = document.getElementById("reasonId").value;
var msql = "SELECT Pid FROM tPid WHERE Reason = 'reason'";
sql = "action=getReasonForBTI&sql=" + encodeURIComponent(msql);
objAjaxAd.main_flag = "getReasonForBTI";
objAjaxAd.SendQuery(sql);
}
$(document).ready(function() {
Puma.getReasonForBTI()
});
修改强>
另外,我会自己发送reason
并在服务器端清理它,然后将其放入查询中。通过Javascript / AJAX发送SQL查询只是在寻找麻烦。
仿皮代码:
sql("
SELECT Pid
FROM tPid
WHERE Reason = ?
", $ajax.reason)
DOUBLE EDIT
此外,将reason
放在字符串中的单引号中不会评估reason
的值。刚想我会为你节省一些未来的头痛
var foo = "bar";
console.log("The value of foo is 'foo'");
=> "The value of foo is 'foo'"
console.log("The value of foo is " + foo);
=> "The value of foo is bar"
答案 1 :(得分:1)
尝试使用Chrome浏览器和开发工具(F12)。
<强>更新强>
var reason = document.getElementById("reasonId").value;
// reason is entered directly byy a user (or Mr. EvilHacker).
var msql = "SELECT Pid FROM tPid WHERE Reason = 'reason'";
// Here you create a SQL, which may sounds like this:
SELECT Pid FROM tPid WHERE Reason = ''; DROP table tPid;--'
如果恶意黑客将';DROP table tPid;--
输入文本框。请查看owasp.org以获取更多信息