0

使用 JQuery .ajax 时,我的内容被放入一个新页面,而不是替换指定的元素。我在同一个站点中使用了非常相似的东西,没有问题,但是这一节不喜欢某些东西并抛出此错误:

Microsoft JScript 运行时错误:预期对象

选择 Continue 后,它将数据加载到新页面而不是指定的选择器中。

我在 _Layout 页面中包含以下内容:

  • < script src="@Url.Content("~/Scripts/jquery-1.7.2.min.js")" type="text/javascript"/>
  • < script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")" type="text/javascript"/>
  • < script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"/>

页面代码如下:

<link href="../../Content/themes/base/jquery.ui.autocomplete.css" rel="stylesheet" type="text/css" />
<link href="../../Content/Tasks.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
$(document).ready(function () {
    $('#btnSaveNewTicket').hide();
    $('#frmTaskDetail').one('submit', function (e) {
        e.preventDefault();
        alert('tru dat');
        $.ajax(
        {
            cache: false,
            async: true,
            type: "POST",
            url: $(this).attr('action'),
            data: $(this).serialize(),
            success: function (data) {
                $('#divTaskDetail').empty();                
                $('#divTaskDetail').html(data);
            },
            complete: function () {
                $('#hidTdAccId').val('');
                $('#hidTdUserId').val('');
                $('#hidTdTicketId').val('');
            }
        });
        return false;
    });

});
</script>

<div id="divTaskDetail">
@using (Html.BeginForm("DetermineTicketAction", "Dispatch", FormMethod.Post, new { id = "frmTaskDetail" }))
{
<div style="background-color: #2C6B87; width: 99%; border: 1px black solid; text-align: left; text-indent: 5px; margin: 1% 0 0 0; padding: 5px 0 5px 0; font-size: 12px; color: white; font-weight: bold">
    Task Details
</div>
<div style="width: 99%; border: 1px black solid;">

    @Html.Hidden("AccountId")       
    @Html.Hidden("ContactId")
    @Html.Hidden("CompanyId")
    @Html.Hidden("TicketId")
    @Html.Hidden("TicketCreated")
    @Html.Hidden("Created")
    @Html.Hidden("TicketClosed")
    @Html.Hidden("isActive")

    <table id="tblTaskDetail" style="width: 100%; text-indent: 5px; color: White; margin: 0 auto; font-size: 12px; top: 0; left: 0;">                    
                <tr>
                    <td>Ticket ID</td>
                    <td>@Html.TextBox("TicketId" ,null, new { @disabled = true })</td>
                    <td>Address</td>
                    <td>@Html.TextBox("Address", null, new {@disabled = true })</td>

                </tr>
                <tr>
                    <td>Date Created</td>
                    <td>@Html.TextBox("Created",null, new { disabled = true })</td>
                    <td>City</td>
                    <td>@Html.TextBox("City",null, new { disabled = true })</td>
                </tr>
                <tr>
                    <td>Company Name</td>
                     <td>@Html.TextBox("CompanyName")<input type="button" id="addCompany" value="+" /></td>
                    <td>State</td>
                    <td>@Html.TextBox("State",null, new { disabled = true })</td>
                </tr>
                <tr>
                    <td>Customer Name</td>                    
                    <td>@Html.TextBox("ContactName")<input type="button" id="addContact" value="+" /></td>
                    <td>Zip Code</td>
                    <td>@Html.TextBox("ZipCode", null, new { disabled = true })</td>
                </tr>
                <tr>
                    <td>Category</td>
                    <td>@Html.DropDownList("CategoryId")</td>
                    <td>Phone Number</td>
                    <td>@Html.TextBox("Phone", null, new { disabled = true })</td>
                </tr>
                <tr>
                    <td>Status</td>
                    <td>@Html.DropDownList("StatusId")</td>
                    <td>E-mail</td>
                    <td>@Html.TextBox("Email", null, new { disabled = true })</td>
                </tr>
                <tr>
                    <td>Priority</td>
                    <td>@Html.DropDownList("PriorityId")</td>
                    <td>Paid</td>
                    <td>@Html.DropDownList("Paid")</td>
                </tr>
                <tr>
                    <td>Task Description</td>
                    <td>@Html.Editor("Description")</td>
                    <td>Assign To</td>
                    <td>@Html.DropDownList("UserId")</td>
                </tr>       
    </table>
    <table style="width: 100%; text-indent: 5px; color: White; margin: 0 auto; font-size: 12px; top: 0; left: 0;">
        <tr>
            <td>Comments @Html.TextBox("Comments", "", new { style = "width: 15%" })</td>
         </tr>
        <tr>
            <td> 
                @Html.ListBox("CommentList", @ViewBag.CommentList as IEnumerable<SelectListItem>, new { id="CommentList", style = "font-size: 10px" })
            </td>
        </tr>
    </table>

    <input type="hidden" id="hidTdAccId" name="hidTdAccId" value="" />
    <input type="hidden" id="hidTdUserId" name="hidTdUserId" value="" />
    <input type="hidden" id="hidTdTicketId" name="hidTdTicketId" value="" />
    <input type="hidden" id="hidSubType" name="hidSubType" value="" />
</div>

<input type="submit" id="btnSave" name="btnSave" value="Save" />
<input type="button" id="btnClearTicket" name="btnClearTicket" value="New Ticket"/>
<input type="submit" id="btnSaveNewTicket" name="btnNewTicket" value="Save New Ticket" />
<input type="submit" id="btnGetDetail" name="btnGetDetail"  style="visibility: hidden"  />
}
</div>

任何帮助/想法表示赞赏。谢谢!

4

1 回答 1

0

出于某种原因,Jquery ajax 在 chrome/safari 中运行良好,但不适用于 IE。用 Ajax 助手替换 JQuery Ajax 为我解决了问题。

感谢您的帮助和建议。为您的时间和智能方法+1。

于 2012-08-28T21:52:24.177 回答