我正在运行一个简单的AJAX请求:
function makePages(num) {
var conn = new XMLHttpRequest();
conn.onreadystatechange = function() {
if (conn.status === 200 && conn.readyState === 4) { //error here
$('#oldPost').before(conn.responseText);
}
else{
return
}
}
conn.open('GET','includes/feedExtra.php?num=' + num);
conn.send();
}
Run Code Online (Sandbox Code Playgroud)
代码运行正常,PHP返回正确的内容.但是,Chrome的控制台出错:
未捕获错误:InvalidStateError:DOM异常11
它指向这一行:
if(conn.status === 200 && conn.readyState === 4){
我究竟做错了什么?
好吧所以我正在尝试将调整大小的画布图像作为文件上传到Flask.
首先,我尝试使用canvas.toDataURL()
它将其转换为base64(?)字符串,然后尝试使用formdata
AJAX 将其作为图像上传,没有运气.
然后我尝试使用此函数将base64转换为blob:
function toblob(stuff) {
var g, type, bi, ab, ua, b, i;
g = stuff.split(',');
if (g[0].split('png')[1])
type = 'png';
else if (g[0].split('jpeg')[1])
type = 'jpeg';
else
return false;
bi = atob(g[1]);
ab = new ArrayBuffer(bi.length);
ua = new Uint8Array(ab);
for (i = 0; i < bi.length; i++) {
ua[i] = bi.charCodeAt(i);
}
b = new Blob([ua], {
type: "image/" + type
});
return b;
}
Run Code Online (Sandbox Code Playgroud)
不是形象......
这是我使用的ajax表单:
s = new FormData();
s.append('image', …
Run Code Online (Sandbox Code Playgroud) 你会如何使用blade的@import方法做到这一点?我试过了:
@if (@include('/path/to/phpfile'))
@include('/path/to/phpfile')
@else
<h2>Oops! It doesn't look like this page exists!</h2>
@endif
Run Code Online (Sandbox Code Playgroud)
也试过file_exists()
,没有骰子:(
ajax ×2
javascript ×2
php ×2
blade ×1
canvas ×1
flask ×1
if-statement ×1
include ×1
laravel ×1
python ×1