无法通过AJAX发送参数本身就是一个页​​面 [英] unable to send parameter through ajax to a page itself

查看:115
本文介绍了无法通过AJAX发送参数本身就是一个页​​面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在keyup事件参数发送给自己的页面。

I am sending parameter to a page itself on keyup event.

我送,虽然阿贾克斯参数如 URL:HTTP://localhost/application/views/pages/users/tags.php tagfilter = LIF,

I am sending a parameter though ajax like url:"http://localhost/application/views/pages/users/tags.php?tagfilter=lif",

和获取其值在一个JavaScript函数('/指令/ showtags /<?PHP的,如果(使用isset($ _ GET ['tagfilter'])及和放大器; $ _GET ['tagfilter ] ==){回声$ _GET ['tagfilter'];}>?',{

and getting its value in a javascript function ('/instruction/showtags/<?php if( isset($_GET['tagfilter']) && $_GET['tagfilter'] == "") {echo $_GET['tagfilter'];} ?> ', {

我查了一下,我的控制台,它显示出任何错误和放大器;没有任何警告。 但我敢肯定它要么不发送参数,也可能是它没有得到参数。

I checked,my console , its showing no errors & no warning. But i am sure its either not sending parameter or it may be its not getting the parameter.

请让我知道,为什么我的参数不发送?是编写Ajax code的方式是正确的?

Please let me know , why my parameter is not sending ? Is the way of writing ajax code is correct?

如果你无法理解我的问题,那么请让我知道,我将试图解释它在一些其他的方式。

全部来源$ C ​​$ C:

Full Source code:

tags.php

 <input placeholder="Search" id="tagfilter" name="tagfilter" type="text"/>

jQuery的/ AJAX功能

   <script type="text/javascript"> 
      $(document).ready(function() {    
      $('#tagfilter').keyup(function(e){
       // alert("called"); 
        $.ajax({
            url:"http://localhost/application/views/pages/users/tags.php?   
       tagfilter=lif",
            type:"get",  
            success: function(){ 

            } 
        });
    });
 });     
</script>

我的无限滚动的js文件,其中包括在同一个页面

My Infinite scroll js file, including in the same page

 <script>
         (function($) { 
                $.fn.scrollPagination = function(options) {

                        var settings = { 
                                nop     : 10, // The number of posts per scroll to be loaded
                                offset  : 0, // Initial offset, begins at 0 in this case
                                error   : 'No More Data To Display!', // When the user reaches the end this is the message that is
                                                            // displayed. You can change this if you want.
                                delay   : 500, // When you scroll down the posts will load after a delayed amount of time.
                                               // This is mainly for usability concerns. You can alter this as you see fit
                                scroll  : true // The main bit, if set to false posts will not load as the user scrolls. 
                                               // but will still load if the user clicks.
                        }

                         .............................
                         .............................
                         .............................

更新:

究竟我试图做的?

我实现了一个无限滚动使用jQuery。当我的页面加载,它叫我的控制器,并从控制器需要的数据,并在我看来,页面显示出来。

I have implemented a infinite scroll with jquery. When my page loads, it call my controller, and from from controller it takes data and display it in my view page.

现在,我打算把搜索这个页面无限滚动的。 我有一个文本框,从这个文本框我试图做搜索的keyup事件。

Now , i plan to put search on this page with infinite scroll. I have a textbox, from this textbox i am trying to do search on keyup event.

我想用这样的逻辑。如果您有什么更好的逻辑,请与我分享,因为我是从很长一段时间努力实现这一点。

I am trying with this logic. If you have any better logic, please share with me,because i am struggling from long time to implement this.

推荐答案

确定。我不知道你的结构,所以我有什么是一些提示。

Ok. I don't know your structure so what I have is few tips.

首先:你需要知道的JavaScript处理比PHP快很多,只要JS是客户端语言时,PHP是服务器端语言。所以尽量让你的PHP数据在JavaScript瓦尔这样的:

First: you need to know that javascript processing is much faster than PHP as long as JS is a Client Side language when PHP is Server Side language. so try to keep your php data in javascript vars like this:

var seg3 = "<?php echo $this->uri->segment(3) ?>";
$.post("/instruction/showtags/" + seg3, {...etc

那么您的安全只是试图检查是否需要所有的URL不只是它的一部分(取决于CI配置),这样你的code能想出这样

then for your safety just try to check whether you need all the url not just part of it ( depends on CI configuration ) so your code can come up like this

var seg3 = "<?php echo $this->uri->segment(3) ?>";
var myurl = "<?php echo site_url('casting/send_email'); ?>" + seg3;
$.post(myurl, {...etc

和一定不要使用 $ _ GET

其次,要确保你发送的段和它的存在。你可以随时使用 的console.log()在javascript跟上数据,看看它是否是空的。

Second, make sure you're sending the segment and it's there. you can always use the console.log() in javascript to keep up with the data and see if it's empty or not.

您是否希望它在KEYUP或KEYDOWN或任何这将是一样的。

whether you want it on keyup or keydown or whatever it will be the same.

如果你正在使用的 JSON 请一定要为最后一个参数添加到您的 $。员额()方法,你可以看到 jQuery的API 它。

and if you are using json make sure to add it as the last arg to your $.post() method you can see the jquery api for it.

这篇关于无法通过AJAX发送参数本身就是一个页​​面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆