0

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

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");
           }
        });
    });
};
4

1 回答 1

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 ?
于 2013-10-23T18:22:43.990 回答