简体   繁体   English

通过Ajax成功附加HTML

[英]Appending HTML through Ajax Success

I would like to know how I can append information through my Ajax on its success. 我想知道如何通过我的Ajax附加有关成功的信息。 This is what I have: 这就是我所拥有的:

HTML/PHP BUTTON: HTML / PHP按钮:

<input class="canjear btn" type="button" value="<?php echo JText::_('COM_CUPHONEO_BOTON_CANJEAR'); ?>" data-id="<?php echo $valor->item_id; ?>" />

JAVASCRIPT CODE: JAVASCRIPT代码:

<script>
jQuery(function(){
    jQuery(".canjear").click(function(e){
        if(this.tagName==="A"){
            e.preventDefault();
        }

//$(this).data("key") will return the value at the named data which is set by HTML5 data-* attribute
        jQuery.ajax({
            url: "index.php?option=com_cuphoneo&task=miscuponess.canjearCupon",
            type: "POST",
            data: {id:jQuery(this).data("id")},
            success: window.location.href = "index.php?option=com_cuphoneo&view=miscuponess&layout=default"
        })
        .done(function(data){
            alert(data);
            }
        });
    });
});
</script>

PHP FUNCTION CALLED: PHP函数调用:

This is a big function but summarizing, it a query which returns data and besides other validations are made. 这是一个很大的功能,但概括来说,它是一个返回数据的查询,并进行了其他验证。

If you need more information please let me know 如果您需要更多信息,请告诉我

The information im trying to append is what I get in the PHP Function which is called in the Ajax. 我试图附加的信息就是我在Ajax中称为PHP Function获得的信息。

Thanks. 谢谢。

@MONZTAA @MONZTAA

You are trying to use both the function which is alternate to each other. 您正在尝试使用两个互为替代的功能。

Deprecation Notice: The jqXHR.success(), jqXHR.error(), and jqXHR.complete() callbacks are deprecated as of jQuery 1.8. 弃用通知:从jQuery 1.8开始,不再使用jqXHR.success(),jqXHR.error()和jqXHR.complete()回调。 To prepare your code for their eventual removal, use jqXHR.done(), jqXHR.fail(), and jqXHR.always() instead. 要准备将其最终删除的代码,请改用jqXHR.done(),jqXHR.fail()和jqXHR.always()。

In turn you should use only this : 反过来,您应该只使用此:

$.ajax({

url: "index.php?option=com_cuphoneo&task=miscuponess.canjearCupon",
type: "POST",
data: {id:jQuery(this).data("id")}
})
.done(function( msg ) {
   alert( "Data Saved: " + msg );
});

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

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