RS together with ajax and javascript's blob object, doesn't work

I trying to download file by using javascript's Blob object, but something weird is happening. First of all I use JAX-RS to send the file from backend, this is my code: Workbook wb = new HSSFWorkbook(); //creating workbook... ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { wb.write(bos); bos.close(); } catch(Exception e) { e.print

RS与ajax和javascript的blob对象一起,不起作用

我试图通过使用JavaScript的Blob对象下载文件,但有些奇怪的事情正在发生。 首先我使用JAX-RS从后端发送文件,这是我的代码: Workbook wb = new HSSFWorkbook(); //creating workbook... ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { wb.write(bos); bos.close(); } catch(Exception e) { e.printStackTrace(); } byte[] bytes = bos.toByteArray(

Using jQuery's ajax method to retrieve images as a blob

I recently asked another (related) question, which lead to this follow up question: Submitting data instead of a file for an input form Reading through the jQuery.ajax() documentation (http://api.jquery.com/jQuery.ajax/), it seems the list of accepted dataTypes doesn't include images. I'm trying to retrieve an image using jQuery.get (or jQuery.ajax if I have to), store this image in a

使用jQuery的ajax方法将图像作为blob进行检索

我最近问了另一个(相关的)问题,导致了这个后续问题:提交数据而不是输入表单的文件 通过阅读jQuery.ajax()文档(http://api.jquery.com/jQuery.ajax/),似乎接受的数据类型列表不包括图像。 我试图使用jQuery.get(或者如果必须的话,jQuery.ajax)来检索图像,将此图像存储在Blob中,并在POST请求中将其上传到另一台服务器。 目前,它看起来像是由于数据类型不匹配,我的图像最终被破坏(字节大小不匹配等)。 执

How can I add a custom HTTP header to ajax request with js or jQuery?

有谁知道如何使用JavaScript或jQuery添加或创建自定义HTTP标头? There are several solutions depending on what you need... If you want to add a custom header (or set of headers) to an individual request then just add the headers property: // Request with custom header $.ajax({ url: 'foo/bar', headers: { 'x-my-custom-header': 'some value' } }); If you want to add a default header (or set o

我如何添加一个自定义的HTTP头到JS或JQuery的AJAX请求?

有谁知道如何使用JavaScript或jQuery添加或创建自定义HTTP标头? 有几种解决方案取决于你需要什么... 如果您想要将自定义标题(或标题集)添加到单个请求中,请添加headers属性: // Request with custom header $.ajax({ url: 'foo/bar', headers: { 'x-my-custom-header': 'some value' } }); 如果你想为每个请求添加一个默认的头文件(或者一组头文件),那么使用$.ajaxSetup() : $.ajaxSetup({ headers: {

How do I get the name of an object's type in JavaScript?

有没有Java的class.getName()的JavaScript等价物? Is there a JavaScript equivalent of Java's class.getName() ? No . ES2015 Update : the name of class Foo {} is Foo.name . The name of thing 's class, regardless of thing 's type, is thing.constructor.name . Builtin constructors in an ES2015 environment have the correct name property; for instance (2).constructor.name is "Numbe

我如何在JavaScript中获取对象类型的名称?

有没有Java的class.getName()的JavaScript等价物? 有没有Java的class.getName()的JavaScript等价物? 没有 。 ES2015更新 : class Foo {}的名称是Foo.name 。 名称thing的类,不管thing的类型,是thing.constructor.name 。 ES2015环境中的内建构造函数具有正确的name属性; 例如(2).constructor.name是"Number" 。 但是,这里有各种各样的黑客以各种方式跌倒: 这里有一个破解你需要的东西 - 注意它修改

How to delay the .keyup() handler until the user stops typing?

I've got a search field. Right now it searches for every keyup. So if someone types “Windows”, it will make a search with AJAX for every keyup: “W”, “Wi”, “Win”, “Wind”, “Windo”, “Window”, “Windows”. I want to have a delay, so it only searches when the user stops typing for 200 ms. There is no option for this in the keyup function, and I have tried setTimeout , but it didn't work.

如何延迟.keyup()处理程序,直到用户停止键入?

我有一个搜索栏。 现在它搜索每个键盘。 因此,如果有人输入“Windows”,它将使用AJAX搜索每个关键字:“W”,“Wi”,“Win”,“Wind”,“Windo”,“Window”,“Windows”。 我想要延迟,所以它只会在用户停止输入200毫秒时进行搜索。 在keyup函数中没有这个选项,我尝试了setTimeout ,但它没有工作。 我怎样才能做到这一点? 我使用这个函数来达到同样的目的,在用户停止输入指定的时间后执行一个函数: var delay = (function

Ajax login issues

I'm having issues with an Ajax login function. There was another question similar to mine that I was able to find but it proved no use. I have no idea what is the issue, this works on another program as well with no issues, hopefully someone can see my mistake From testing I think the issue is in the "checkLogIn" function because when I run the application the alert within the

Ajax登录问题

我遇到了Ajax登录功能问题。 还有另一个类似于我能找到的问题,但它没有用。 我不知道是什么问题,这对另一个程序也有效,没有问题,希望有人能看到我的错误 从测试中我认为问题出现在“checkLogIn”函数中,因为当我运行应用程序时,函数中的警告显示 阿贾克斯: $("#checkLogIn").click(function() { $.ajax({ type: 'POST', contentType: 'application/json', url: rootURL + '/logIn/',

jquery Ajax Doesn't Send JSON Data

I am trying to send an ajax send request, but it always goes into error . $('form#contactForm button.submit').click(function () { var contactName = $('#contactForm #contactName').val(); var contactEmail = $('#contactForm #contactEmail').val(); var contactSubject = $('#contactForm #contactSubject').val(); var contactMessage = $('#contactForm #conta

jQuery的Ajax不发送JSON数据

我试图发送一个ajax发送请求,但它总是error 。 $('form#contactForm button.submit').click(function () { var contactName = $('#contactForm #contactName').val(); var contactEmail = $('#contactForm #contactEmail').val(); var contactSubject = $('#contactForm #contactSubject').val(); var contactMessage = $('#contactForm #contactMessage').val();

PHP and jQuery Ajax not doing anything

I made a test page (my first test of PHP) using AJAX and jQuery to call a PHP function in my main document. Unlike all the other answers on how this is done, my PHP and HTML are in the same file (phptest.php). When I click my button to submit a form (this is a really simple test- I click a button and something happens- I KNOW I should have used javascript) I can see in Firebug's panel that

PHP和jQuery Ajax没有做任何事情

我做了一个测试页面(我的第一个PHP测试),使用AJAX和jQuery在我的主文档中调用PHP函数。 与所有其他解决方案不同,我的PHP和HTML位于相同的文件(phptest.php)中。 当我点击我的按钮提交表单时(这是一个非常简单的测试 - 我点击一个按钮,发生了一些事情 - 我知道我应该使用javascript)我可以在Firebug的面板中看到该帖子已发送,但没有任何反应页面,所以我相信这是PHP端的问题。 有人可以帮我解决问题,或者给我一些关

Error 415: x

The web service accepts application/json , but $.ajax() with dataType : 'json' set just tries to send data as application/x-www-form-urlencoded . What's the trick here? dataType: 'json' specifies that jQuery expects JSON back from the server (see docs). In order to specify that you are sending JSON, you need to add contentType: "application/json" . Furthermore,

错误415:x

Web服务接受application/json ,但带有dataType : 'json' $.ajax()集试图发送数据为application/x-www-form-urlencoded 。 这里有什么窍门? dataType: 'json'指定jQuery期望从服务器返回JSON(请参阅文档)。 为了指定您要发送JSON,您需要添加contentType: "application/json" 。 此外,jQuery不能将对象转换为JSON。 如果您将任何对象传递给data ,则需要自行将其对齐: data: JSON.stringi

How to achieve the same behaviour in Ajax

$usrname = $this->session->userdata('username'); $password = $this->session->userdata('password'); $data = array('userName'=>urlencode($usrname),'password'=>urlencode($password)); $data_string = json_encode($data); $datanew = "loginemployee=". $data_string; $method = 'post'; $format = 'application/json'; $this->rest->format($format); $login_url = $this->login_url; //pr

如何在Ajax中实现相同的行为

$usrname = $this->session->userdata('username'); $password = $this->session->userdata('password'); $data = array('userName'=>urlencode($usrname),'password'=>urlencode($password)); $data_string = json_encode($data); $datanew = "loginemployee=". $data_string; $method = 'post'; $format = 'application/json'; $this->rest->format($format); $login_url = $this->login_url; //pr