jQuery-ajax 'on click event' not working
jQuery-ajax 'on click event' not working
我试图使用ajax加载某些页面,但'点击'不工作。我创建了一个init()函数,以便其中一个页面在加载时自动加载。那工作!然而,当我点击任何链接时,什么都没有加载。事实上,什么也没发生。一旦链接被点击,它就不会进入jQuery脚本。任何建议都将不胜感激。
这里是我的链接…
<a href="#" id='add' >Add</a>
<?php foreach($names as $name): ?>
<a href="#" id="<?= $name['id']; ?>" class="league"><?= $name['name']; ?></a>
<?php endforeach; ?>
<section id='main'>Main content</section>
这是我的jQuery脚本…
var app = { // this is a namespace
nav: $('a.league'), // selector
content: $('section#main') // section where id='main'
};
app.putContent = function(content){
this.content.html(content);
}
app.loadPage = function(page){
$.ajax({
url: '../views/security.php',
type: 'GET',
cache: false,
//data:{id: page}, // this works too
data:"id=" + page,
success: function(data){
app.putContent(data);
},
error: function(){
app.putContent('Could not find page.');
}
});
}
app.init = function(){
app.loadPage('add'); // this part works
app.nav.on('click', function(){ // This part(on click) is not working
var page = $($this).attr("id");
app.loadPage(page);
});
}();
改变这一行:
var page = $($this).attr("id");
这:
var page = $(this).attr("id");
提示:
- 使用浏览器检查器/控制台来识别JS中的问题代码
相关文章:
- $rootScope not working
- jQuery document.ready not working
- Javascript getElementsByTagName not working?
- JQuery.val( ) not working
- Tomcat websocket is not working
- Javascript JSON.parse not working
- NodeJS Multer is not working
- Regex not working
- Ember run.debounce not working
- AngularJs 1 not working
- document.getElementById.style.backgroundImage not working
- Rxjs5, distinct() is not working
- createOscillator noteOn not working
- Javascript - .getHours() not working
- Javascript setTimeout not working | onkeydown
- MongoDB $pull not working
- Express router.use not working
- JSONP not working
- window.opener not working in chrome & IE
- Backbone + RequireJS: Collection.each() is not working