Data variable in jquery ajax function

柔情痞子 提交于 2019-12-24 02:45:23

问题


I'm trying to use the code below, but it's not working: UPDATED WORKING:

$(document).ready(function() { 
    $('.infor').click(function () {
     var datasend = $(this).html();
        $.ajax({
            type: 'POST',
            url: 'http://domain.com/page.php',
            data: 'im_id='+datasend',
            success: function(data){
                $('#test_holder').html(data);
            }
            });
    }); 
});

As you can see I used $datasend as the var to send but it doesn't return the value of it, only its name.


回答1:


I would change $datasend = $(this).html; to var datasend = $(this).html();

Next I would change data: 'im_id=$datasend', to data: 'im_id='+datasend,



来源:https://stackoverflow.com/questions/8023275/data-variable-in-jquery-ajax-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!