[英]Using the Data-uri-to-img-url service with jquery jsonp not working
I'm trying to use this to get image URL's http://aminariana.github.io/data-uri-to-img-url/ for sharing on facebook. 我正在尝试使用它来获取图像URL的http://aminariana.github.io/data-uri-to-img-url/以便在Facebook上共享。
I just can't work out how to make the post request using jquery: 我只是不知道如何使用jquery发出发布请求:
# Make a POST request with param 'image[data_uri]' set to the above DataURI input. #在参数'image [data_uri]'设置为上述DataURI输入的情况下发出POST请求。 # This could be from an HTML form with a textarea, or programmatically using an AJAX POST request. #这可以来自带有文本区域的HTML表单,也可以使用AJAX POST请求以编程方式进行。
I have setup a JS Fiddle that creates an image in canvas, converts the image to the datauri http://jsfiddle.net/7asutg7c/ it's just the last part of using jsonp in jquery to send the parameter and get the URL back that I am completely lost on. 我设置了一个JS Fiddle,它在画布上创建图像,将图像转换为datauri http://jsfiddle.net/7asutg7c/,这只是在jQuery中使用jsonp发送参数并获取URL的最后一部分,完全迷失了。
var url = 'http://data-uri-to-img-url.herokuapp.com/images.json';.
$.ajax({
type: 'POST',
url: url,
async: false,
// data: dataURL,
contentType: "application/json",
dataType: 'jsonp',
success: function(json) {
console.log(json.url);
},
error: function(e) {
console.log(e.message);
}
});
My initial thought was to set data to the dataURI but I get "Failed to load resource: the server responded with a status of 414 (Request-URI Too Large)" ... so I am a little stuck about how I should be sending that dataURI. 我最初的想法是将数据设置为dataURI,但是我收到“无法加载资源:服务器响应状态为414(请求URI太大)”……所以我对应该如何发送感到有些困惑该dataURI。
Any help would be greatly appreciated. 任何帮助将不胜感激。
Create a JavaScript object like this, 像这样创建一个JavaScript对象,
var myData = {
image: {
data_uri: your_data_uri_here
}
};
and then pass that as value of the data
parameter of the $.ajax
call. 然后将其作为$.ajax
调用的data
参数的值传递。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.