English 中文(简体)
ajax电击功能中的执行频率?
原标题:executing jquery functions in an ajax callback function?
  • 时间:2011-02-16 21:03:52
  •  标签:
  • jquery
$.ajax({


            type: "POST",
            url: "",
            data:   "callback=delete_contact_us_entry&offset=" + posts + "&numposts=" + num,
            success: function(html){
                jQuery("#output").html(html);


            }

});

This code would execute a callback function called delete_contact_us_entry on a file named ajax.php

我想要做的是,如果成功的话,就能够行使一个 j忙的职能,删除适当的tag子。

哪一个最佳领域来取代 j删除功能? 成功:运行? 你们能否把它放在警示职能中?

而且,如果问答成功或失败,我是否试图退回1或2份,但我是否在“成功:功能(html)”中的讲话不会奏效......是因为“html”是一个目标,不一定是一个变数?

增 编

最佳回答

如果在你听途退步之后,你想做事,那么你就应该把它放在你作为成功手的职司上。 例如:

$.ajax({
   type: "POST",
   url: "",
   data:   "callback=delete_contact_us_entry&offset=" + posts + "&numposts=" + num,      
   success: function(result){
       jQuery("#output").html(result);
       $("#someTable tr:first").remove();
   }
});

如果你的服务器面稿正在退回一些回报价值而不是超文本,我建议将参数重新命名为结果或结果,以避免混淆。 然后,你可以利用成功功能中的这种变数来传播和做不同的工作。

问题回答

您可以检查收益价值,并视此情况,提醒用户注意或删除tr。

        success: function(html){
            jQuery("#output").html(html);

            if(html ==  1 ) {
              // remove tr
            } else {
              alert( error );
            }
        }

此外,在您的1.ajax呼吁中添加“dataType: html,以确保j Query确实将它作为任何情况下的另一种做法。

你可以肯定地将删除逻辑放在退约职能中。

关于您的1或2号返回问题,它应当与作为数据Type的html合作,但是,你必须牢记,这是一个扼杀,不是第1号或第2号,因此你必须使用。

if (html == "1")

rather than

if (html == 1) // or if (html)

There might also be some issues if your html contains other characters (like ), they might interfere with your if conditionals. Take a look at ajax dataType (http://api.jquery.com/jQuery.ajax/), you might want to consider returning a json object from your php (using json_encode) so you can have a nice object on the javascript side.





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签