Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在第二次ajax调用之后,jquery不起作用_Javascript_Jquery_Ajax_Asp.net Mvc - Fatal编程技术网

Javascript 在第二次ajax调用之后,jquery不起作用

Javascript 在第二次ajax调用之后,jquery不起作用,javascript,jquery,ajax,asp.net-mvc,Javascript,Jquery,Ajax,Asp.net Mvc,我在asp.NETMVC中通过ajax获得了一个部分,第一次和第二次都很好,但在那之后,它重定向到通过ajax获取页面的页面安装 这是我的部分页面代码: <script> var jqgd = jQuery.noConflict(); jqgd(function () { jqgd('#getdata-@ViewBag.term').on('click', 'a', function () { if (this.href ==

我在asp.NETMVC中通过ajax获得了一个部分,第一次和第二次都很好,但在那之后,它重定向到通过ajax获取页面的页面安装

这是我的部分页面代码:

<script>

    var jqgd = jQuery.noConflict();
    jqgd(function () {
        jqgd('#getdata-@ViewBag.term').on('click', 'a', function () {
            if (this.href == "") { return; }
            jqgd.ajax({
                url: this.href,
                type: 'GET',
                cache: false,
                success: function (result) {
                    alert(result);
                    jqgd('#retrieve-@ViewBag.term').html(result);
                }
            });
            return false;
        });
    });
</script>

<script type='text/javascript'> // Added
    jQuery(function ($) {

        $("div, p, a, b, strong, bold, font, span, td")
        .filter(function () {
            return $(this).children(":not(.word)").length == 0
        })
        .each(function () {
            this.innerHTML = $(this).text().replace(/\S+/g, function (word) {
                return "<span class='word'>" + word + "</span>";
            });

            $(".word", this).filter(isEnglish).addClass('english');
            $(".word", this).filter(isPersian).addClass('persian');
        });

        function isEnglish() {
            return $(this).text().charCodeAt(0) < 255;
        }

        function isPersian() {
            return $(this).text().charCodeAt(0) > 255;
        }
    });
</script>

<div id="retrieve-@ViewBag.term">
    <div style="float:right;">
        <div class="searchtitles" style="float: right;">@ViewBag.term</div>
        <table class="jjt" cellpadding="0" cellspacing="0">
            <tr class="j2t">
                <td class="j13t">field</td>
                <td class="j13t">field</td>
                <td class="j13t">field</td>
                <td class="j13t">field</td>
                <td class="j13t">field</td>
                <td class="j13t">field</td>
                <td class="j13t">field</td>
            </tr>
            @foreach (var item in ViewBag.Terms)
            {
                Mydata 
            }


        </table>

        <div id="getdata-@ViewBag.term" style="float:left; direction:ltr; margin-left:-20px; margin-top:-15px;">@Html.PagedListPager((IPagedList)ViewBag.Tours, page => Url.Action("results", new { page }))</div>
    </div>
</div>

var jqgd=jQuery.noConflict();
jqgd(函数(){
jqgd('#getdata-@ViewBag.term')。在('click','a',函数(){
如果(this.href==“”){return;}
jqgd.ajax({
url:this.href,
键入:“GET”,
cache:false,
成功:功能(结果){
警报(结果);
jqgd('#retrieve-@ViewBag.term').html(结果);
}
});
返回false;
});
});
//增加
jQuery(函数($){
$(“div,p,a,b,strong,bold,font,span,td”)
.filter(函数(){
返回$(this.children(“:not(.word)”)。长度==0
})
.每个(功能){
this.innerHTML=$(this.text().replace(/\S+/g,函数(word){
返回“+word+”;
});
$(“.word”,this.filter(isEnglish).addClass('english');
$(“.word”,this.filter(isPersian.addClass('persian');
});
函数为英语(){
返回$(this).text().charCodeAt(0)<255;
}
函数isPersian(){
返回$(this).text().charCodeAt(0)>255;
}
});
@ViewBag.term
领域
领域
领域
领域
领域
领域
领域
@foreach(ViewBag.Terms中的var项)
{
我的数据
}
@PagedListPager((IPagedList)ViewBag.Tours,page=>Url.Action(“结果”,新建{page}))
我正在使用pagedlist,当我第二次更改页面时,所有的jquery命令似乎都终止了,这是什么问题? 有人能帮我吗

编辑:这部分代码在第二次调用后不起作用

<script type='text/javascript'> // Added
        jQuery(function ($) {

            $("div, p, a, b, strong, bold, font, span, td")
            .filter(function () {
                return $(this).children(":not(.word)").length == 0
            })
            .each(function () {
                this.innerHTML = $(this).text().replace(/\S+/g, function (word) {
                    return "<span class='word'>" + word + "</span>";
                });

                $(".word", this).filter(isEnglish).addClass('english');
                $(".word", this).filter(isPersian).addClass('persian');
            });

            function isEnglish() {
                return $(this).text().charCodeAt(0) < 255;
            }

            function isPersian() {
                return $(this).text().charCodeAt(0) > 255;
            }
        });
    </script>
//添加
jQuery(函数($){
$(“div,p,a,b,strong,bold,font,span,td”)
.filter(函数(){
返回$(this.children(“:not(.word)”)。长度==0
})
.每个(功能){
this.innerHTML=$(this.text().replace(/\S+/g,函数(word){
返回“+word+”;
});
$(“.word”,this.filter(isEnglish).addClass('english');
$(“.word”,this.filter(isPersian.addClass('persian');
});
函数为英语(){
返回$(this).text().charCodeAt(0)<255;
}
函数isPersian(){
返回$(this).text().charCodeAt(0)>255;
}
});
您的
#getdata-@ViewBag.term
位于
#retrieve-@ViewBag.term
元素中,但在第一次调用后会被替换。您需要使用事件委派

请尝试以下方法:

jqgd('#retrieve-@ViewBag.term').on('click', '#getdata-@ViewBag.term a', function () {
    ...
}

这只是在黑暗中拍摄:


从单击处理程序中获取e,然后尝试e.preventDefault();在返回false之前。

您是否尝试了
live('click')
而不是
@madhushankarox:它不起作用……我的页面中有一部分jquery代码,in也不起作用。我把它复制到我的问题中,请告诉我出了什么问题?你应该创建一个新问题,而不是编辑这个问题。在这里,您可以解释代码应该做什么。另外,它更有可能被其他人看到,并使你的问题的范围保持集中。我创建了一个新问题,请帮助