当前位置: 首页 > 工具软件 > jQuery Upvote > 使用案例 >

php显示jquery未定义,运行PHP脚本时,jQuery函数表示未定义

元阳荣
2023-12-01

我基本上是这样做的,所以当您单击按钮进行“投票”时

目前我有

clients.php

$clientInfo = "SELECT * FROM Clients ORDER BY Client ASC";

$stmt = sqlsrv_query($conn, $clientInfo);

echo "

";

while ($client = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC))

{

echo "

" .

"

"

" . $client['Client'] . "
" .

"


";

}

echo "

";

?>

如您在上方看到的,有一个onclick forvotUp()函数.

在页面底部,我有

并在scripts.js中(我从有关单击div运行php文件的教程中获得了voteUp()的知识)

$(document).ready(function()

{

$('.pull-me').click(function()

{

$('.panel1').slideToggle('fast')

});

$('.pull-me').click(function()

{

$('.panel2').slideToggle('fast')

});

$('.pull-me').click(function()

{

$('.panel3').slideToggle('fast')

});

$("#selection-box1").change(function()

{

document.location.href = $(this).val();

});

$(".output").click(function ()

{

var noteid = $(this).data("noteid");

var templatenoteid = $(this).data("templatenoteid");

var variablenoteid = $(this).data("variablenoteid");

if ($(this).data("noteid"))

{

$("#right-box").load("noteContent.php", {noteid: noteid});

}

else if ($(this).data("templatenoteid"))

{

$("#right-box").load("templateNoteContent.php", {templatenoteid: templatenoteid});

}

else

{

$("#right-box").load("variableContent.php", {variablenoteid: variablenoteid});

}

});

var modal = document.getElementById('login-box');

window.onclick = function(event)

{

if (event.target == modal)

{

modal.style.display = "none";

}

}

//This script votes up and down for the client

function voteUp()

{

$.get("voteup.php");

return false;

}

function voteDown()

{

$.get("votedown.php");

return false;

}

});

最后在voteup.php中

if (isset($_POST['clientid']))

{

$voteup = "UPDATE Clients SET Pos = (SELECT MAX(Pos) FROM Clients) + 1 WHERE ClientID = " . $_POST['clientid'];

$stmt = sqlsrv_query($conn, $voteup);

}

else

{

echo "No ClientID";

}

?>

当我单击带onclick =“ voteUp()”的DIV的Vote Up按钮时

为什么在控制台中出现错误,提示“ ReferenceError:未定义表决”

解决方法:

您已经确定了方法的范围.

相反,您可以将它们附加到Windows,以便可以从任何地方访问.

window.voteUp = function()

{

$.get("voteup.php");

return false;

}

window.voteDown = function()

{

$.get("votedown.php");

return false;

}

标签:php,jquery,sql,ajax

来源: https://codeday.me/bug/20191013/1905109.html

 类似资料: