jqxhr

When performing post via ajax, Bad Request is returned instead of the JSON result

被刻印的时光 ゝ 提交于 2019-11-28 20:03:24
问题 Javascript jqXHR = $.ajax({ url: $frm.attr("action"), type: "POST", dataType: "json", cache: false, headers: headers, contentType: "application/json;charset=UTF-8", data: ko.mapping.toJSON(data, map), beforeSend: function(x) { if (x && x.overrideMimeType) { return x.overrideMimeType("application/json;charset=UTF-8"); } } }); jqXHR.fail(function(xhr, err, msg) { /* xhr.responseText NEED TO BE JSON!!! */ }); In Chrome Headers Request Method:POST Status Code:400 Bad Request Request Headersview

JS: how to encode an image.png into base64 code for data URI embedding?

眉间皱痕 提交于 2019-11-27 16:59:39
问题 I have several .png bitmaps of different dimensions, by example ./img/dog.png and ./img/cat.png . How to load the base64 string of my images via JS ? My expected data is omething like that (but far longer): data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAB9AAAAfQCAYAAACaOMR5AAAgAElEQ…ECBAgQIECAAAECBAgQIECAAAECBAgQIECAAAECBAicCwy83crEe3e04AAAAABJRU5ErkJggg== Note: I wish to get back this string which is my file and just my file, not clipped, nor bigger. I will then embedded it into a SVG <image>

OPTIONS 405 (Method Not Allowed) regardless server sends Access-Control-Allow-Methods:OPTIONS, GET, HEAD, POST

馋奶兔 提交于 2019-11-27 16:20:09
问题 I'm trying to make cross-domain request and my server is configured to send the following headers: Access-Control-Allow-Credentials:true Access-Control-Allow-Headers:x-requested-with, Authorization Access-Control-Allow-Methods:OPTIONS, GET, HEAD, POST Access-Control-Allow-Origin:* But when an OPTION request is made, I get OPTIONS 405 (Method Not Allowed) error. Any Ideas what is the problem and how to fix it? 回答1: I would suggest 2 solutions: 1) If you are using WebAPI you need to implement

jQuery.post( ) .done( ) and success:

六眼飞鱼酱① 提交于 2019-11-27 07:04:38
jQuery documentation on jQuery.post( ) // Assign handlers immediately after making the request, // and remember the jqxhr object for this request var jqxhr = $.post( "example.php", function() { alert( "success" ); }) .done(function() { alert( "second success" ); }) .fail(function() { alert( "error" ); }) .always(function() { alert( "finished" ); }); // Perform other work here ... // Set another completion function for the request above jqxhr.always(function() { alert( "second finished" ); }); What is the difference between the success: parameter and the jqXHR.done( ) method; if there is none,

jQuery.post( ) .done( ) and success:

放肆的年华 提交于 2019-11-26 22:16:03
问题 jQuery documentation on jQuery.post( ) // Assign handlers immediately after making the request, // and remember the jqxhr object for this request var jqxhr = $.post( "example.php", function() { alert( "success" ); }) .done(function() { alert( "second success" ); }) .fail(function() { alert( "error" ); }) .always(function() { alert( "finished" ); }); // Perform other work here ... // Set another completion function for the request above jqxhr.always(function() { alert( "second finished" ); });