按钮onclick ajax调用

I am trying to put together a webpage that has multiply pages in 1 file which checks the session that i've created to show a page according to the session value.
However, i want to create a button that does a ajax call on the background and returns the results thought JSON, BUT i don't know if i'm doing it the right way.
I have this js:

$(document).ready(function() {
var alert = $('.Cmessage'); // DIV TO PUSH RESULTS TO

$("#terug").on('click', function(){

$.ajax({
  url: 'http://www.XXX.nl/shop/offerte/back.php', // form action url
  type: 'get', // form submit method get/post
  dataType: 'json', // request type html/json/xml 
  beforeSend: function() {
    alert.fadeOut();
  },
success: function(result) {
    if(result.error){
        alert.html(result.html).fadeIn();
        console.log(e)
    }else{
        alert.html(result.html).fadeIn();
        }
    }
});
});
});

This js needs to check whenever i click on:

<button type="button" class="terug">Open/Laden</button>

But somehow i fail to get it attached to the class "terug" and do something with it.

Does anybody has any suggestions/idea's on how i can do this better and get it working ? :P

Greetings.

查看全部
douzhan1031
douzhan1031
2015/02/05 14:56
  • php
  • javascript
  • jquery
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

5个回复