将URL拖放到浏览器中并使用jQuery处理 [英] Drag and Drop a URL into a browser and process using jQuery
问题描述
我需要能够将URL(从浏览器中的URL栏)拖放到网页中,使用该链接向Web服务发出请求,并接受JSON答复并填充表格.
I need the ability to drag and drop a URL (from the url bar in a browser) into a web page, make a request to a web service using that link, and take the JSON reply and populate a form.
我已经能够创建用于处理链接的Web服务,并且能够使用jQuery.ajax发出请求,但是我不确定如何与已删除的链接进行交互.
I have been able to create the web service that processes the link, and I have been able to use jQuery.ajax to make requests, but I am unsure as to how to interact with a dropped link.
有人可以给我指出一个例子吗?我该怎么用?
Can anyone point me to an example of this? What should I use?
我已经能够使用"drop"启动我的ajax查询,但是我不确定如何获取已删除的URL的值.这是我的代码:
I have been able to fire off my ajax query using "drop", but I am unsure about how to get the value of the URL that I have dropped. Here is my code:
jQuery(function() {
$("input").bind("drop", function(e){
var val = e.dataTransfer.getData('Text')
$.ajax({
type: 'GET',
url: 'http://dev.null:8888/gud/',
data: 'url=' + val,
dataType: 'json',
success: function(jsonData) {
alert(jsonData);
},
error: function (xhr, ajaxOptions, thrownError){
alert("this isnt working");
},
});
});
});
我以为e.dataTransfer.getData('Text')
可以让我访问URL的值,但事实并非如此.有谁知道我如何获得该价值?
I thought that e.dataTransfer.getData('Text')
would let me access the URL's value, but it doesn't. Does anyone know how I can access that value?
找到了.是e.originalEvent.dataTransfer.getData('Text')
推荐答案
有趣的问题.我相信这是可能的;但是,我确实认为存在一些限制的可能性.
Interesting question. I believe that this is possible; However I do think that there is a possibility for some limitations.
据我所知,大多数平台/浏览器在拖放文本内容(例如,原始文本,URL,炸鱼和薯条"等)方面的行为都类似.将一些文本拖放到文本框中,该文本框中将填充该内容.因此,您可以指示用户将链接/文本放到特定的文本区域...
As far as I know, most platforms/browsers behave in a similar manner with regard to dragging and dropping text content (be it raw text, url's, "fish and chips", etc...) As soon as you "drop" some text into a textbox, the textbox will be populated with that content. So you could instruct your users to drop the link/text on to a specific textarea...
关于检测何时发生丢弃,我认为您将不得不依靠setInterval
方法来检查某个文本框的值/内容,以知道何时插入了有效的URL.
With regard to detecting when the drop occurs I think you will have to rely on a setInterval
method checking the value/contents of a certain textbox to know when a valid URL has been inserted.
*现在,关于局限性-我不知道(浮现在头)此功能是否确实是通用的,但我确实相信这是所有主要"功能的标准功能浏览器,它不涉及平台.
* 很乐意从知识渊博的人那里得到一些确认.
这篇关于将URL拖放到浏览器中并使用jQuery处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!