简体   繁体   English

Jquery Load 返回 [object object]

[英]Jquery Load returns [object object]

I am using Jquery to load my summernote module with text from a text file , however when i execute my function it recognizes the load as an object instead of displaying the text in the document.我正在使用 Jquery 将文本文件中的文本加载到我的 summernote 模块,但是当我执行我的函数时,它将加载识别为一个对象,而不是在文档中显示文本。

How can i get jquery to return the text inside of the file instead of the file as an object.我怎样才能让 jquery 返回文件内部的文本而不是文件作为对象。

function testing(){

    let word = $('.summernote6').load('http://127.0.0.1:8887/js/summernote/cats.txt');

    $('.summernote6').summernote('insertText', word);
    console.log(word)
}

Then console displays [object object]然后控制台显示[object object]

Turns out i just needed to interact with the text content of the object so the below code worked for me.原来我只需要与对象的文本内容进行交互,所以下面的代码对我有用。

function testing(){

   let word = $('.summernote6').load('http://127.0.0.1:8887/js/summernote/cats.txt');
   let words = word.text();

    $('.summernote6').summernote('insertText', word.text());
    console.log(word.text())
}

The load method loads a content in an selector. load 方法在选择器中加载内容。

You can only do:你只能这样做:

function testing(){
    $('.summernote6').load('http://127.0.0.1:8887/js/summernote/cats.txt');
}

It will load the content of cats.txt inside the .summernote6 element这将加载.summernote6元素中cats.txt的内容

You are getting an Object because the variable is receiving the selector with the content already inserted您正在获取一个对象,因为该变量正在接收已插入内容的选择器

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

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