jQuery onclick不发送数据

时间:2013-10-23 18:16:56

标签: javascript jquery ajax

为什么我在下面收到以下错误:

Uncaught TypeError: Object [object global] has no method 'data'

HTML:

$attributes = array('class' => 'main post', 'onsubmit' => 'validateModules(event)', 'dataid' => $moviesparx_website_id); echo form_open("admin/websites/{$website_id}/page/op/{$action}/{$id}", $attributes); ?>

    <ul style="width: 25%; border-right: 1px solid #ccc; padding-right:10px;" class="postForm">
        <li>
            <input style="width:100%;" placeholder="Page Title" id="post_title" name="post_title" onclick="urlCheck()" dataid="<?php echo website_id;?> type="text" value="<?php echo set_value('post_title', $post['post_title']); ?>" />
            <?php echo form_error('post_title'); ?>
        </li>

JS:

function urlCheck()
{
      var id = self.data("id");

        $(".postForm").on('click', '#post_title', function(e){
        e.preventDefault();
        $.ajax({
           url      : '<?=base_url()?>/page/op',
           data     : { post_title : $("#post_title").val(), 'website_id' : id },
           type     : 'POST',
           success  : function(resp){
                alert( resp );
           },
           error    : function(resp){
                console.log("Error in ajax request");
           }
        });
    });
};

1 个答案:

答案 0 :(得分:1)

function urlCheck() {
    var id = self.data("id");

    $(".postForm").on('click', '#post_title', function (e) {
        e.preventDefault();
        $.ajax({
            url: '<?=base_url()?>/page/op',
            data: {
                post_title: $("#post_title").val(),
                    'website_id': id
            },
            type: 'POST',
            success: function (resp) {
                alert(resp);
            },
            error: function (resp) {
                console.log("Error in ajax request");
            }
        });
    });
}

urlCheck(); <-- did you add this line ?