json - 如何在ajax中将字符串保持为原始格式?
问题描述
我通过 ajax 请求发送一些值,如下所示:
$('#compileBtn').on('click', function(evnt){
evnt.preventDefault();
var souceCode = cEditor.getValue();
console.log(souceCode);
var button = $(this),
ajax_url = '<?php echo admin_url("admin-ajax.php"); ?>',
data = {
action: 'get_output_by_ajax',
sourceCode : souceCode,
lang: 2,
testcases: ["1"],
security: '<?php echo wp_create_nonce("get_output"); ?>'
};
$.post(ajax_url, data, function (response) {
// obj = JSON.parse(response);
console.log(response);
}).always(function () {
$('.result-processing').addClass('hide');
});
});
我只是将收到的值返回如下: function get_states_by_ajax_callback(){
check_ajax_referer('get_output','security');
$sourceCode = $_POST['sourceCode'];
echo $sourceCode; wp_die();
}
看看,我使用了两个console.log()分别在ajax请求之前和通过console.log(souceCode);
和 获取ajax请求之后打印值console.log(response);
。但souceCode
已更改如下:
发送ajax请求之前:
#include<iostream>
using namespace std;
int main()
{
cout<<"Hello Wold!"<<endl<<"How are you?";
return 0;
}
收到ajax请求后
#include<iostream>
using namespace std;
int main()
{
cout<<\"Hello Wold!\"<<endl<<\"How are you?\";
return 0;
}
这意味着在“之前添加反斜杠。我怎样才能保持不变或将其转换为原始形式?
解决方案
推荐阅读
- android - 尝试在空对象引用上调用虚拟方法“void android.widget.RadioGroup.check(int)”
- javascript - javascript代码在创建的形状上弹跳球
- python-3.x - 计算 Pandas Dataframe 中每几列的平均值
- activemq - ActiveMq - 持久主题 - 并发
- r - 在某些条件下使用带有 R 的 aggregate() 函数聚合行,而不使用 dplyr
- flutter - 如何刷新小部件?
- botframework - 本地聊天机器人无法从团队接收消息
- java - 将嵌套的 foreach 循环转换为流
- jquery - 我的窗口滚动得很好,但是滚动鼠标后似乎迷失方向,我无法单击按钮,因为鼠标的位置很奇怪
- vba - 在使用变量更改表单中的字段时更新表/表单中的选定数据