简体   繁体   English

如何在 JQuery 中使用 ajax

[英]how to use ajax in JQuery

I have that works fine without Script manager.在没有脚本管理器的情况下,我可以正常工作。 but if I add script manager that getting an error: sys undefined.但是,如果我添加出现错误的脚本管理器:sys undefined。

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Block-ui-pageload.aspx.cs" Inherits="Block_ui_pageload" %>

<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script src="Scripts/jquery-1.3.2.js" type="text/javascript"></script>
    <script src="Scripts/jquery.blockUI.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
        <div id="divConfirmBox1">
            <asp:GridView ID="gvCategories" runat="server" AutoGenerateColumns="false">
                <Columns>
                    <asp:TemplateField HeaderText="Category Name">
                        <ItemTemplate>
                            <asp:Label ID="lblCategoryName" runat="server" Text='<%# Eval("CategoryName") %>' />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <input type="button" value="Delete" onclick="showDeleteConfirmation('<%# Eval(" CategoryId")=CategoryId") %=% />')" />
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
            &nbsp;
            <div id="divConfirmBox" style="display:none">
                Are you sure you want to delete this record?
                <input type="button" value="No" />
            </div>
        </div>
    </form>
</body>
</html>

<script language="javascript" type="text/javascript">
    $(function () {
        $('#divConfirmBox1').block({ message: $('#divConfirmBox') });
    });

    $(function () {
        $('#divConfirmBox').click(function (event) {
            $('#divConfirmBox1').unblock();
        });
    });
</script>

initially during the page load .最初在页面加载期间。 I am blocking the screen(PAge).我挡住了屏幕(页面)。 once the user clicks the button the page is unblocked.一旦用户点击按钮,页面就会被解锁。 is there anything wrong in the Syntax whiling working with Ajax script manager使用 Ajax 脚本管理器时,语法有什么问题吗

You should move the jQuery code into $(document).ready.您应该将 jQuery 代码移动到 $(document).ready 中。 I suspect you're preventing certain scripts from loading appropriately by running the code inline rather than in .ready.我怀疑您通过运行内联代码而不是 .ready 来阻止某些脚本正确加载。 I'm running the same version of jQuery (but not UI block) with ScriptManager in 3.5 right now, no prob.我现在正在 3.5 中使用 ScriptManager 运行相同版本的 jQuery(但不是 UI 块),没有问题。

AJAX is not a thing - its a bunch of technologies put together to achieve asynchronous communication. AJAX 不是一个东西——它是一堆技术放在一起来实现异步通信。 Yes, you have some JavaScript coding in there, but none of them actually do anything 'ajaxian' - a good example of something really AJAX-style would be an validation of a (registration) form or something like that.是的,您在那里有一些 JavaScript 编码,但它们实际上都没有做任何“ajaxian” - 真正 AJAX 风格的一个很好的例子是(注册)表单的验证或类似的东西。 You'd set some oberservers for some fields and validate them whilst the user is still making inputs on other fields...您将为某些字段设置一些观察者并在用户仍在其他字段上进行输入时对其进行验证...

I think what you're looking for is noConflict .我认为你正在寻找的是noConflict It's been a while since I've used asp.net ajax but if I'm not mistaken, there is a $ function defined.自从我使用 asp.net ajax 已经有一段时间了,但如果我没记错的话,定义了一个$函数。

In the web.config we need to add the follwing code within tag.在 web.config 中,我们需要在标签中添加以下代码。

then the problem was solved那么问题就解决了
every thing was working fine一切正常

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

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