Javascript 突出显示word并发送GET请求
我在Django模型中创建了一个文本字段。我想在单击单词时突出显示单词。我找到了 当选择一个单词从其他网站API接收JSON时,如何调整它以向Django发送GET请求?提前谢谢Javascript 突出显示word并发送GET请求,javascript,jquery,django,Javascript,Jquery,Django,我在Django模型中创建了一个文本字段。我想在单击单词时突出显示单词。我找到了 当选择一个单词从其他网站API接收JSON时,如何调整它以向Django发送GET请求?提前谢谢 $(函数(){ editTxt(“#myTxt”); editTxt(“#myTxtDiv”); $('span').live('mouseover',function(){ $(this.addClass('hlight'); }); $('span').live('mouseout',function(){ $(t
$(函数(){
editTxt(“#myTxt”);
editTxt(“#myTxtDiv”);
$('span').live('mouseover',function(){
$(this.addClass('hlight');
});
$('span').live('mouseout',function(){
$(this.removeClass('hlight');
});
});
函数editTxt(选择器){
$(函数(){
var newHtml='';
var words=$(选择器).html().split(“”);
对于(i=0;i
您可以使用以下方法执行类似操作:
注意您必须将数据对象text
属性替换为您的API后端参数接受的任何属性,如注释中所述,您不需要.live()
确保用后端API URL替换
您的\u DJANGO\u API\u URL
您可以使用以下方法执行类似操作:
注意您必须将数据对象text
属性替换为您的API后端参数接受的任何属性,如注释中所述,您不需要.live()
确保将
您的\u DJANGO\u API\u URL
替换为您的后端API URL如何调整它以发送GET请求
使用。还要注意,jQuery1.6.2已经过时了将近9年。您应该在3.x分支上更新它。您还需要删除live()
并改用。如何调整它以发送GET请求
使用。还要注意,jQuery1.6.2已经过时了将近9年。您应该在3.x分支上更新它。您还需要删除live()
,并改用。
...
$("span").on("mouseover", function() {
xhr = $(this).addClass("hlight");
$.ajax({
method: "post",
url: "YOUR_DJANGO_API_URL",
data: { text: $(this).text() },
success: function(data) {
// replace HTML element or whatever.
console.log(data);
}
});
});
$("span").on("mouseout", function() {
xhr.abort();
$(this).removeClass("hlight");
});
...