- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我读过的关于这个问题的所有帖子都是因为传递的对象包含其他对象,而不是原始值。
我的数据对象都是原始值,但它仍然不起作用。
代码如下:
function ImageUploader(imgEl, params) {
this.imgEl = imgEl;
this.params = params;
this.params["Function"] = "saveImage";
}
// send data from asynchronously uploaded image (as image URI)
// to PHP script which will write data to file
ImageUploader.prototype.uploadImage = function () {
var iu = this;
var fileReader = new FileReader();
fileReader.onload = function (e) {
iu.params["Image"] = e.target.result;
console.log(iu.params);
$.ajax({
type: "POST",
url: "/scripts/php/Form.php",
data: iu.params,
success: alert,
error: function (jqXHR, status, error) {
console.log(error, this);
}
});
};
this.params["FileName"] = this.imgEl.files[0].fileName || this.imgEl.files[0].name;
fileReader.readAsDataURL(this.imgEl.files[0]);
};
这是一个它拒绝的示例对象:
{
FileName: "Matrix.jpg",
Function: "saveImage",
ID: 10,
Image: "data:image/jpeg;base64,...",
Line: 1,
Name: "Test Form"
}
最佳答案
此错误与您的 iu.params
对象无关。错误在于这一行:
success: alert,
需要在窗口
的“上下文”中调用window.alert()
(或只是alert()
)函数对象。
当您执行success:alert
时,jQuery 会在运行 AJAX 请求的 jqXHR 对象的上下文中调用成功回调。像这样的事情:
success.call(jqXHR, data)
我不知道 jQuery 使用的确切代码
因此,您的 alert
是在错误的“上下文”中调用的,因此会引发错误。要修复此问题,只需将匿名函数传递给 success
:
success: function(data){
alert(data);
}
或者,如果您确实想要,您可以使用.bind()
来确保在右侧调用alert()
上下文:
success: alert.bind(window)
如果您真的 真的想要保持成功:警报
,那么您可以告诉 jQuery 在正确的上下文中调用它,方法是添加context: window
到您的 $.ajax
调用。
请注意,alert.bind()
(以及 context: window
)可能无法在所有浏览器中工作,因此不能建议。我建议您使用如图所示的匿名函数。
关于javascript - jQuery ajax 未捕获类型错误 : Illegal invocation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27801864/
#include #include using namespace std; //void multiply(int b); int main() { float total = 0; flo
我正在尝试加载存储在 HDFS 中的 Hadoop 集群上的 informatica 日志文件。我在 Python 中使用 subprocess 来执行此操作,但相信由于文件名而出现错误,我不确定如何
我尝试制作用于 Symfony 2 上传的 ajax 脚本。Chrome 返回此错误: Uncaught TypeError: Illegal invocation jquery.min.js:4 我
这只是一个简单的代码,用于检查一个数字是否是质数,我不知道这是编译器还是代码的问题。如果您能提供一些帮助,我们将不胜感激。 这是代码: #include "stdio.h" int main() {
当我运行这个 bash 脚本时: if [ [$EUID -ne 0] ]; then echo "This script must be run as root" 1>&2 exit 1
我最近偶然发现了 this jcstress 中的示例: @JCStressTest @State @Outcome(id = "10", expect =
我不理解这个错误(C2100:非法间接)。我标记了三个实例——都在底部附近。我在网上看过,我知道这与我的指示有关,但在 8 小时后,我完全迷路了。这里可能还有其他一些错误,但我什至无法分辨,因为我无法
我们正在运行一个 Create React App (CRA) Web 应用程序,我们已向其中添加了 Google Analytics v4。我们使用 ga-4-react 启动分析npm 包。 in
我想将多个图像对象发布到 testphp.php。但控制台打印错误说非法调用。 我已经尝试过: submit $("#sub").click(function(){ // get th
当文本框为空时尝试禁用按钮时,我在 google chrome 控制台中收到此错误: function isEmpty() { var r = document.getElementById;
我只是在玩 timesheet.js的源代码(参见具体行)并遇到一个小错误,请参见下面的代码行: '', 当我生成 HTML 并将其分成两行时,一切正常,但如果我执行以下操作将
public class Flatten { public static int[] flatten(int[][] x) { int totalLength = 0;
我的计算机上有一个 python3 脚本,我可以使用 python3motion_detection.py 运行它,并且该脚本有效,我尝试在我的 Raspberry 上使用它,但失败并显示消息非法指令
我正在尝试最近学到的一些多线程概念,但无法运行它。 它给出了 IllegalMonitorStateException 但没有弄清楚错误发生的原因。 因此,关于代码2线程引用名称填充器和写入器都共享一
这是 html 这是脚本 $('#submit').click(function() { var files = $("[type='file']")[0].fil
我尝试通过ajax提交表单,下面是表单。 Date Upload File
我几天前买了 C++ Primer 这本书,我开始学习这门新语言了! 此刻,我想弄明白为什么我自己写的这个 block 是非法的: 我将一个 const int 初始化为 512;我初始化一个指向 n
我收到以下错误消息 [Err] 1267 - Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,C
我正在尝试使用本教程创建一个 PostgreSQL 数据库: http://tutorials.jumpstartlab.com/topics/environment/environment.html
我想弄乱 Speech Recognition API,所以我从简单的页面开始,该页面在单击 body 元素时开始识别。我的 scripts.js 文件是: var recognition = new
我是一名优秀的程序员,十分优秀!