首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未定义EncodeURIcomponent

未定义EncodeURIcomponent
EN

Stack Overflow用户
提问于 2016-03-20 23:48:44
回答 1查看 8.6K关注 0票数 2

我正在播放GreaseMonkey沙箱,试图制作一个脚本,将加载的页面转发到另一台服务器,以便通过POST进行处理。下面是剧本:

代码语言:javascript
复制
// ==UserScript==
// @name        Mirror Page
// @namespace   mailto:linkhyrule5@gmail.com
// @description POSTs page to dynamic page mirror
// @include     http://*
// @include     https://*
// @version     1
// @grant       GM_xmlhttpRequest
// ==/UserScript==

var ihtml = document.body.innerHTML;
GM_xmlhttpRequest({
    method: 'POST',
    url: 'http://localhost:5723/index.php',
    data: "PageContents=" + encodeURIcomponent(ihtml) + "\nURL=" + encodeURIcomponent(document.URL),
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
});

不知何故,我得到了encodeURIcomponent is not defined,尽管它是一个全局函数,应该可以在JavaScript所在的任何地方使用。我想我是误会什么了?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-20 23:51:49

你忘了资本C..。就像骆驼箱:

代码语言:javascript
复制
var ihtml = document.body.innerHTML;
GM_xmlhttpRequest({
    method: 'POST',
    url: 'http://localhost:5723/index.php',
    data: "PageContents=" + encodeURIComponent(ihtml) + "\nURL=" + encodeURIComponent(document.URL),
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
});
票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36121072

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档