用ajax调用加载php文件并执行按钮单击事件 [英] Loading php file with ajax call and performing button click event
问题描述
在我的start.php中,我在按钮单击事件中调用了一些功能.
In my start.php I was calling few function on button click event.
此函数正在从其中包含的.js文件中调用其他一些函数.
This function was calling some other functions from .js file included in it.
现在,我创建了新文件login.php.在此上,当用户执行成功登录时,我通过ajax调用加载了start.php.
Now I created new file login.php. On this when user perform successful login I load start.php through ajax call.
但是现在当我单击按钮时,它说:
But now when I click button it says :
Uncaught TypeError: Object [object Object] has no method 'rateit'
尽管我在login.php中包含了.js文件和功能.
Though I have included .js files and functions in login.php.
这是它们两者的链接:
login.php- https://gist.github.com/karimkhanp/74b81267c4ae870dd432
login.php - https://gist.github.com/karimkhanp/74b81267c4ae870dd432
start.php- https://gist.github.com/karimkhanp/94a601d5bf9f5bb2dee0
start.php - https://gist.github.com/karimkhanp/94a601d5bf9f5bb2dee0
推荐答案
登录页面加载后,无法将您为起始页面创建的功能绑定到尚不存在的元素.例如,元素#rateit99
不能在login.php中的脚本中使用,因为该页面加载时不存在.
When the login page loads it can't bind the functions you are creating for the start page to the elements that don't yet exist. For instance the element #rateit99
can't be used in the script in login.php because it doesn't exist when that page loads.
您需要将与start.php相关的脚本部分移回到该php文件中.这样,当通过ajax加载start.php时,它将正确地绑定功能.
You need to move the script part that relates to the start.php back into that php file. This way when it loads start.php through ajax it will bind the functions correctly.
这篇关于用ajax调用加载php文件并执行按钮单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!