小编The*_*ebs的帖子

Ajax在控制台中没有给我任何东西?

更新的问题,以更好地反映社区的支持

基于社区支持,我已将Ajax功能更改为:

(function($){   
    $(document).ready(function(){
        $('a').click(function(e){
          var el = $(this).prev('input[type="checkbox"]');
          if(el.is(':checked')){
               el.prop('checked',false);   
          }
          $.ajax({
              url  : "http://localhost/wordpress/wp-content/themes/Aisis-Framework/CoreTheme/AdminPanel/Template/Helper/UncheckPackageThemeHelper.php",
              type : 'GET',
              data : { 'element_name' : el.prop('name') },      
              success: function(data, textStatus, jqXHR){
                console.log(data);
              },
              error: function(jqXHR, textStatus, errorThrown ){
                console.log(jqXHR, textStatus, errorThrown);
              } 
          });
          e.preventDefault();
        });
    }); 
 })(jQuery);
Run Code Online (Sandbox Code Playgroud)

生成的PHP类是这样的:

class CoreTheme_AdminPanel_Template_Helper_UncheckPackageThemeHelper{

    private $_element_name = null;

    public function __construct(){
        if(isset($_GET['element_name'])){
            $this->_element_name = $_GET['element_name'];
            echo $this->_element_name;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

网络选项卡显示我有一些激活Jquery的输出,我在下面显示:

在此输入图像描述

控制台没有错误地吐出,但没有回显元素名称.我已经阅读了Jquery Ajax API,到目前为止,我所做的一切似乎都是正确的.然而,我没有得到理想的出局.

注意:响应选项卡为空....换句话说,我没有收到回复.

php ajax jquery jconsole

0
推荐指数
1
解决办法
150
查看次数

检查 rails 中是否已存在日志文件

我希望执行以下操作:

new_logger = Logger.new('log/exceptions.log')
new_logger.level = Logger::ERROR
new_logger.error('THIS IS A NEW EXCEPTION!')

ActiveRecord::Base.logger = new_logger
Run Code Online (Sandbox Code Playgroud)

但我只希望创建该日志文件,如果它不存在。我真的只是使用File.exist?

你会如何测试这个?(使用 rspec),如果日志文件变大,rails(或者是 Web 服务器)会压缩文件并创建一个新文件,例如:log.zip, log_2

ruby logging rspec ruby-on-rails

0
推荐指数
1
解决办法
880
查看次数

为什么东西会在标签之外回显?

所以我有一个方法可以根据你传入的属性数组创建一个文本元素,除了value属性之外它都有效,但问题如下:

如果某个值,无论是函数,文本还是你"回调"出来的东西,那么值会显示在框的旁边,如果返回值,那么我们得到标记内的值.

function textarea(array $attributes){

   if(isset($attributes['name'])){
       $this->name = 'name="'.$attributes['name'].'"';
   }

   if(isset($attributes['id'])){
       $this->id = 'id="'.$attributes['id'].'"';
   }

   if(isset($attributes['class'])){
       $this->class = 'class="'.$attributes['class'].'"';
   }else{
       $this->class = 'class="aisisTextElement"';
   }

   if(isset($attributes['rows'])){
       $this->rows = 'rows="'.$attributes['rows'].'"';
   }

   if(isset($attributes['cols'])){
       $this->cols = 'cols="'.$attributes['cols'].'"';
   }

   if(isset($attributes['value'])){
       $this->value = $attributes['value'];
   }

   if(isset($attributes['style'])){
       $this->style = 'style="'.$attributes['style'].'"';
   }

   $build_aisis_element = '<textarea ' 
                          .$this->id 
                          .$this->class 
                          .$this->name 
                          .$this->rows  
                          .$this->cols 
                          .$this->style
                          .'>'.$this->value . '</textarea>';                
   echo $build_aisis_element;
} 
Run Code Online (Sandbox Code Playgroud)

例如:

如果此函数作为值传入:

function echo_me(){
    echo "hello"
}
Run Code Online (Sandbox Code Playgroud)

我的HTML看起来像:

hello
<textarea></textarea>
Run Code Online (Sandbox Code Playgroud)

怎么样

function return_me(){
    return "hello"
}
Run Code Online (Sandbox Code Playgroud)

我的HTML是:

<textarea>hello</textarea>
Run Code Online (Sandbox Code Playgroud)

为什么是这样?

html php forms

-1
推荐指数
1
解决办法
84
查看次数

预期 () 但发现一个结构

我有一个世界对象:

use rand::{thread_rng, Rng};

use super::world::World;

pub struct Worlds {
    worlds: Vec<World>
}

impl Worlds {
    pub fn new(world: Vec<World>) -> Worlds {
        Worlds { worlds: world }
    }

    pub fn get_random_world(&self) -> World {
        let mut rng = thread_rng();

        if self.worlds.len() > 0 {
            let world_index: usize = rng.gen_range(0, self.worlds.len());

            self.worlds[world_index]
        }

        self.worlds[0]
    }
}
Run Code Online (Sandbox Code Playgroud)

该结构Worlds采用称为结构的向量World(如果需要,我可以发布该代码)。

get_random_world应该返回一个World结构,并且使用self.worlds[world_index],但显然它期望一个().

我迷路了; 我告诉它返回什么,它返回那个但它期望不同的东西?

use rand::{thread_rng, Rng};

use super::world::World;

pub struct Worlds { …
Run Code Online (Sandbox Code Playgroud)

rust

-1
推荐指数
1
解决办法
3243
查看次数

以下throws'是一个方法但被视为类型'

我在ASP中遇到的最令人困惑的错误.我之前已经完成了这样的方法调用,并且在我的代码的其他位置没有问题.

首先是班级:

namespace LocApp.Helpers.Classes.LocationHelper
{
    public class QueryHelper
    {
        private LocAppContext db = new LocAppContext();

        public static IEnumerable<Service> getAllService()
        {
            using (var db = new LocAppContext())
            {
                var service = db.Locations.Include(s => s.LocationAssignment);

                var serv = (from s in db.Services
                            where s.active == true
                            select s).ToList();
                return serv;
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

很容易理解发生了什么.所以我们调用方法:

IEnumerable<LocApp.Models.Service> Service = new LocApp.Helpers.Classes.LocationHelper.QueryHelper.getAllService(Model.id);
Run Code Online (Sandbox Code Playgroud)

getAllServices(Model.id) 抛出错误"是一种方法,但被视为一种类型",嗯,不,它不被视为一种类型....

这是怎么回事?

c# entity-framework asp.net-mvc-3

-4
推荐指数
1
解决办法
111
查看次数