English 中文(简体)
• 如何在JQuery发出多次但分开的AJAX电话
原标题:How to make multiple, but separate AJAX calls in JQuery

我正试图使用塔顿语分别发出2个AJAX电话。 我想发生的情况是:当Button1被点击的产品Table显示网络服务的数据时;当Button2被点击时,其他可点显示其自己的网络服务数据。 但是,现在,当阿顿被点击时,没有任何迹象显示。 我知道,如果只有一部法典,则该法典就行了,而它并没有围绕一个浮标功能进行总结。

无错误信息。 ASP.NET 4.0, JQuery 1.4.4. Not using gustManager. 不使用更新小组。

法典如下:

<script src="Scripts/jquery-1.4.4.js" type="text/javascript"></script>
<script src="Scripts/jquery.tmpl.js" type="text/javascript"></script>
<script id="ProductsTemplate" type="text/x-query-tmpl">
    <tables id="ProductsTemplate">            
        <thead>
        </thead>
        <tbody>
            {{each d}}
                {{tmpl($value)  #ProductsRowTemplate }}
            {{/each}}
        </tbody>         
    </tables>
</script>
<script id="ProductsRowTemplate" type="text/x-query-tmpl">
    <tr>
        <td>${title}</td>
        <td>${size}</td>
        <td>${price}</td>
    </tr>
</script>
<script id="Products2Template" type="text/x-query-tmpl">
    <tables id="Products2Template">            
        <thead>
        </thead>
        <tbody>
            {{each d}}
                {{tmpl($value)  #Products2RowTemplate }}
            {{/each}}
        </tbody>         
    </tables>
</script>
<script id="Products2RowTemplate" type="text/x-query-tmpl">
    <tr>
        <td>${title}</td>
        <td>${size}</td>
        <td>${price}</td>
    </tr>
</script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#Button1").click(function () {
            $.ajax({
                type: "POST",
                url: "JSON-WebService.asmx/getProducts",
                data: "{}",
                contentType: "application/json; charset=UTF-8",
                dataType: "json",
                success: function (data) {
                    $( #ProductsTemplate ).tmpl(data).appendTo( #ProductsTable );
                    alert("Products works");
                },
                failure: function (data) {
                    alert("Products didn t work");
                }
            });
        });

        $("#Button2").click(function () {
            $.ajax({
                type: "POST",
                url: "JSON-WebService.asmx/getProducts",
                data: "{}",
                contentType: "application/json; charset=UTF-8",
                dataType: "json",
                success: function (data) {
                    $( #Products2Template ).tmpl(data).appendTo( #OthersTable );
                    alert("Products2 works");
                },
                failure: function (data) {
                    alert("Products2 didn t work");
                }
            });
        });

    });
</script>
<title>Using JQuery</title>

<form id="form1" runat="server">

<div id="ProductsTable">

</div>

<div id="OthersTable">

</div>

<div>
    <asp:Button ID="Button1" runat="server" Text="Products" />
    <asp:Button ID="Button2" runat="server" Text="Products2" />
</div>

</form>
最佳回答

Ok. 我发现,BA:Button在发出亚克斯呼吁后造成后退/重载。 因此,它只字未提。 答案是:

`<script type="text/javascript">
$(document).ready(function () {
    $("#Button1").click(function (evt) {
        evt.preventDefault();
        $.ajax({
            type: "POST",
            url: "JSON-WebService.asmx/getProducts",
            data: "{}",
            contentType: "application/json; charset=UTF-8",
            dataType: "json",
            success: function (data) {
                $( #ProductsTemplate ).tmpl(data).appendTo( #ProductsTable );
                alert("Products works");
            },
            failure: function (data) {
                alert("Products didn t work");
            }
        });
    });
 });
</script>`
问题回答

正如我所说的那样,我看着蚊帐小组,看看看这些结果是否被点击。 如果他们来到你,则在《html法典》中有点。

仅去掉你的约束性和警惕性,看看它是否印刷。 然后,你可以轻易打印。

利用火力、蚊帐小组,你可以轻易解决问题。

利用我撰写的以下职能:

    function jqajax(urlp,thediv) {
          $.ajax({
            type: "GET",
            url: urlp,
            dataType: "html",
            //data: "header=variable",
            success: function(data){
                if($( # +thediv)) 
                {

                  $("#"+thediv).html(data);

                } 
                else 
                {

                  $("#"+thediv).parent().html(data);
                }
            }
          }); 
}

页: 1

onclick="jqajax(yoururlhere,returedhtml_div_here);”





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签