html - 尝试发送和返回原始 html 时,Ajax 调用不起作用
问题描述
我正在使用 Ajax 调用来调用 C# 方法,该方法通过删除不需要的 html 标记和属性来处理用户粘贴输入。
当我使用 html 格式(标签和属性)粘贴内容时,我的 Ajax 调用不起作用。您能否建议如何为这种情况定义 Ajax 参数(将原始 html 发送到服务器端代码并返回原始 html)?
看法:
@(Html.Kendo().Editor()
.Name("myEditor")
.PasteCleanup(p => p.Custom("myPasteCleanUp")
)
脚本:
function myPasteCleanUp(input) {
var response = null;
if (input != null) {
$.ajax({
type: "POST",
url: '/Home/htmlTagCleanUp',
data: { userInput: input },
async: false,
success: function (response) {
input = response;
},
});
}
return input;
}
控制器:
[HttpPost]
[AllowAnonymous]
public ActionResult htmlTagCleanUp(string userInput)
{
userInput = userInput;
return Content(userInput, "text/html");
}
解决方案
阻止您的 AJAX 调用的原因是您添加了 if 条件:
if (html != null) {
}
你能告诉我html变量是在哪里定义的吗?尽管如此,我认为您正在尝试检查输入的空值,如果我们在它应该工作的条件下用输入变量替换html :
if (input != null) {
}
推荐阅读
- ruby - 为什么在传入 ':css' 时会从 watir-webdriver 方法“assert_valid_as_attribute”中得到一个“无效属性”异常?
- html - 允许在 IE11 中禁用字段集上溢出滚动
- c# - 如何发送列表
到 IN 运算符我的 sql - admob - Admob Android 上 AdFailedToLoad ERROR_CODE_NO_FILL 但没有改变任何东西
- ios - UITabBarController 添加没有标签栏项的视图控制器
- r - 使用 Prophet 交叉验证多个时间序列
- ubuntu - How do I run programs / use SDK? (ubuntu)
- powershell - 为什么 API 调用在 teamcity 中不起作用
- java - 如何从数组对象中删除 £ 符号并保存它?
- .net - 将 .NET Core 登录到文件和控制台 - 带有时间戳