简体   繁体   English

jQuery:在Ajax中加载提示内容

[英]Jquery : Tiptip content loaded in ajax

i would load content of tiptip from ajax but this doesn't work :-/ 我将从ajax加载tiptip的内容,但这不起作用:-/

This is the code : 这是代码:

<div class="maclasse"><a href="#" ajaxparam="monparametre" title="">aaaaaaaa</a></div>
<script>
$(function() {
$(".maclasse a").tipTip({   delay : 200,
        maxWidth : "350px",
        context : this,
        content: function (e) {
                    $.ajax({
                        url: "../front/toto.php?" + $(this).attr('ajaxparam'),
                        cache: false,
                        success: function (response) {
                            e.content.html(response);
                        }
                    });
                    return 'Chargement...';
                }
    });
});
</script>

2 errors insolved from my script : 我的脚本解决了2个错误:

  • the url called by ajax would be front/toto.php?monparametre but it is front/toto.php?undefined 由ajax调用的URL将是front / toto.php?monparametre,但它是front / toto.php?undefined

  • in case of ajax success, the error e.content is undefined is catch 如果ajax成功,则错误e.content未定义为catch

If someone knows the issue, i would be very very happy :-) 如果有人知道这个问题,我会非常高兴的:-)

Sorry for my poor english and thanks for your help. 对不起,我的英语不好,谢谢您的帮助。

Using $(this) inside ajax handler won't work, because it will be assigned to the ajax function itself, and not to html page. 在ajax处理程序中使用$(this)将不起作用,因为它将被分配给ajax函数本身,而不是html页面。 For the second question, try to log the response to the console and check if it has the value you are looking for, maybe it's some sort of misspell error. 对于第二个问题,请尝试将响应记录到控制台,并检查其是否具有所需的值,也许是某种拼写错误。 The code: 编码:

<div class="maclasse"><a href="#" ajaxparam="monparametre" title="">aaaaaaaa</a></div>
<script>
var that = this;    
$(function() {

$(".maclasse a").tipTip({   delay : 200,
    maxWidth : "350px",
    context : this,
    content: function (e) {
                $.ajax({
                    url: "../front/toto.php?" + $(that).attr('ajaxparam'),
                    cache: false,
                    success: function (response) {
                        console.log(response);
                        e.content.html(response);
                    }
                });
                return 'Chargement...';
            }
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM