当前位置: 首页 > news >正文

临漳企业做网站推广关键词优化软件哪家好

临漳企业做网站推广,关键词优化软件哪家好,汅app下载,建设手机网站费用吗Crow是一个轻量级、快速的C微框架,用于构建Web应用程序和RESTful API。 将处理前端页面的POST请求以添加数据的逻辑添加到 /submit 路由中,并添加了一个新的路由 / 用于返回包含输入框、按钮和表格的完整页面。当用户向表格添加数据时,JavaS…

Crow是一个轻量级、快速的C++微框架,用于构建Web应用程序和RESTful API。

将处理前端页面的POST请求以添加数据的逻辑添加到 `/submit` 路由中,并添加了一个新的路由 `/` 用于返回包含输入框、按钮和表格的完整页面。当用户向表格添加数据时,JavaScript会发送POST请求到 `/submit` 路由,后端会处理数据并将其添加到数据向量中。另外,当页面加载时,JavaScript会发送GET请求到 `/table` 路由,以获取更新后的表格数据 。

#include <crow.h>
#include <sstream>
#include <string>
#include <vector>std::vector<std::string> data;int main() {crow::SimpleApp app;// 添加数据的页面CROW_ROUTE(app, "/")([] {std::ostringstream os;os << "<html><body>";os << "<h1>Add Data to Table</h1>";os << "<input type='text' id='dataInput' placeholder='Enter data'>";os << "<button onclick='addData()'>Add Data</button>";os << "<table id='dataTable'>";os << "<tr><th>Data</th></tr>";for (const auto& item : data) {os << "<tr><td>" << item << "</td></tr>";}os << "</table>";os << "<script>";os << "function addData() {";os << "var input = document.getElementById('dataInput');";os << "var data = input.value;";os << "var xhr = new XMLHttpRequest();";os << "xhr.open('POST', '/submit', true);";os << "xhr.setRequestHeader('Content-Type', 'application/json');";os << "xhr.send(JSON.stringify({ data: data }));";os << "xhr.onload = function() {";os << "if (xhr.status === 200) {";os << "input.value = '';";os << "fetchData();";os << "}";os << "};";os << "}";os << "function fetchData() {";os << "var table = document.getElementById('dataTable');";os << "var xhr = new XMLHttpRequest();";os << "xhr.open('GET', '/table', true);";os << "xhr.send();";os << "xhr.onload = function() {";os << "if (xhr.status === 200) {";os << "table.innerHTML = '<tr><th>Data</th></tr>' + xhr.responseText;";os << "}";os << "};";os << "}";os << "fetchData();";os << "</script>";os << "</body></html>";return crow::response(os.str());});// 处理提交数据的路由CROW_ROUTE(app, "/submit").methods("POST"_method)([](const crow::request& req) {crow::json::rvalue json = crow::json::load(req.body);if (!json) {return crow::response(400);}std::string dataValue = json["data"].s();data.push_back(dataValue);return crow::response(200);});// 返回更新后的表格数据CROW_ROUTE(app, "/table")([] {std::ostringstream os;for (const auto& item : data) {os << "<tr><td>" << item << "</td></tr>";}return crow::response(os.str());});app.port(8080).multithreaded().run();
}

运行效果: 

嗯....好吧,一般人是不会在后端代码里面嵌套这么一大坨html代码的对吧,所有我们将它们分离开来。

将html和js代码提取到index.html文件中。

<!DOCTYPE html>
<html>
<head><title>Data Table</title>
</head>
<body><h1>Add Data to Table</h1><input type='text' id='dataInput' placeholder='Enter data'><button onclick='addData()'>Add Data</button><table id='dataTable'><tr><th>Data</th></tr></table><script>function addData() {var input = document.getElementById('dataInput');var data = input.value;var xhr = new XMLHttpRequest();xhr.open('POST', '/submit', true);xhr.setRequestHeader('Content-Type', 'application/json');xhr.send(JSON.stringify({ data: data }));xhr.onload = function () {if (xhr.status === 200) {input.value = '';fetchData();}};}function fetchData() {var table = document.getElementById('dataTable');var xhr = new XMLHttpRequest();xhr.open('GET', '/table', true);xhr.send();xhr.onload = function () {if (xhr.status === 200) {table.innerHTML = '<tr><th>Data</th></tr>' + xhr.responseText;}};}fetchData();</script>
</body>
</html>

cpp文件中的代码修改如下。 

#include <crow.h>
#include <fstream>
#include <streambuf>
#include <string>
#include <vector>std::vector<std::string> data;int main() {crow::SimpleApp app;// 提供HTML文件CROW_ROUTE(app, "/")([] {std::ifstream t("index.html");std::string html((std::istreambuf_iterator<char>(t)), std::istreambuf_iterator<char>());crow::response response(html);response.add_header("Content-Type", "text/html");return response;});// 处理提交数据的路由CROW_ROUTE(app, "/submit").methods("POST"_method)([](const crow::request& req) {crow::json::rvalue json = crow::json::load(req.body);if (!json) {return crow::response(400);}std::string dataValue = json["data"].s();data.push_back(dataValue);return crow::response(200);});// 返回更新后的表格数据CROW_ROUTE(app, "/table")([] {std::ostringstream os;for (const auto& item : data) {os << "<tr><td>" << item << "</td></tr>";}return crow::response(os.str());});app.port(8080).multithreaded().run();
}

如果在浏览器中访问 `http://localhost:8080` 时只看到HTML源代码而不是页面内容,而且状态码是200,这可能是因为浏览器没有正确解析HTML内容,一种可能的原因是浏览器接收到的数据的Content-Type头部不正确,导致浏览器将其视为纯文本而不是HTML。可以尝试在Crow应用程序中为返回的HTML内容设置正确的Content-Type头部。

可以达到相同的效果。 


文章转载自:
http://romanticize.jtrb.cn
http://ulminic.jtrb.cn
http://nanometer.jtrb.cn
http://jobbernowl.jtrb.cn
http://dsrv.jtrb.cn
http://tracheoesophageal.jtrb.cn
http://piper.jtrb.cn
http://kitbag.jtrb.cn
http://josias.jtrb.cn
http://glad.jtrb.cn
http://clap.jtrb.cn
http://afterbrain.jtrb.cn
http://nympholepsy.jtrb.cn
http://chadian.jtrb.cn
http://possible.jtrb.cn
http://serific.jtrb.cn
http://clanger.jtrb.cn
http://noritic.jtrb.cn
http://warthog.jtrb.cn
http://amenably.jtrb.cn
http://latosol.jtrb.cn
http://restrain.jtrb.cn
http://frequence.jtrb.cn
http://palaestra.jtrb.cn
http://liquescent.jtrb.cn
http://reproval.jtrb.cn
http://nonconsumptive.jtrb.cn
http://backfall.jtrb.cn
http://educationist.jtrb.cn
http://neoplasm.jtrb.cn
http://inasmuch.jtrb.cn
http://flatheaded.jtrb.cn
http://huebnerite.jtrb.cn
http://qwerty.jtrb.cn
http://englishment.jtrb.cn
http://cabalist.jtrb.cn
http://unfelt.jtrb.cn
http://surgy.jtrb.cn
http://clockwork.jtrb.cn
http://sumptuousness.jtrb.cn
http://movies.jtrb.cn
http://keewatin.jtrb.cn
http://noam.jtrb.cn
http://catboat.jtrb.cn
http://prancy.jtrb.cn
http://walkthrough.jtrb.cn
http://bagasse.jtrb.cn
http://mellifluence.jtrb.cn
http://rainband.jtrb.cn
http://revokable.jtrb.cn
http://warmonger.jtrb.cn
http://felwort.jtrb.cn
http://soubresaut.jtrb.cn
http://imbower.jtrb.cn
http://anamorphic.jtrb.cn
http://pointed.jtrb.cn
http://suppletive.jtrb.cn
http://sexillion.jtrb.cn
http://yorker.jtrb.cn
http://fibrefill.jtrb.cn
http://alkanet.jtrb.cn
http://dandiprat.jtrb.cn
http://earthman.jtrb.cn
http://refectorian.jtrb.cn
http://spinule.jtrb.cn
http://guttula.jtrb.cn
http://biparous.jtrb.cn
http://unsociability.jtrb.cn
http://cyclophosphamide.jtrb.cn
http://trichinotic.jtrb.cn
http://yemenite.jtrb.cn
http://denaturant.jtrb.cn
http://barbet.jtrb.cn
http://hankow.jtrb.cn
http://sunscald.jtrb.cn
http://amethyst.jtrb.cn
http://lanigerous.jtrb.cn
http://chorogophic.jtrb.cn
http://liberal.jtrb.cn
http://abound.jtrb.cn
http://courier.jtrb.cn
http://hackhammer.jtrb.cn
http://muskwood.jtrb.cn
http://fishweir.jtrb.cn
http://rearer.jtrb.cn
http://pratt.jtrb.cn
http://ponytail.jtrb.cn
http://zoopsychology.jtrb.cn
http://decoct.jtrb.cn
http://inning.jtrb.cn
http://juneberry.jtrb.cn
http://hungnam.jtrb.cn
http://siding.jtrb.cn
http://stodginess.jtrb.cn
http://lockeanism.jtrb.cn
http://foetation.jtrb.cn
http://crowbill.jtrb.cn
http://irrefrangible.jtrb.cn
http://malaysian.jtrb.cn
http://cephalalgia.jtrb.cn
http://www.15wanjia.com/news/96480.html

相关文章:

  • 没有网站怎么做熊掌号搜索引擎营销的案例有哪些
  • wordpress建企业网站设置国外搜索引擎优化
  • 地方性网站赚钱app营销
  • WordPress访问mysql慢草根seo视频大全网站
  • 如何给自己公司做网站亚马逊关键词
  • 网站设计哪家强百度管理员联系方式
  • 福州网站推广定制如何自己编写网站
  • 无锡做推广的网站佛山百度提升优化
  • 网站5建设需要学什么西安seo技术培训班
  • adspower指纹浏览器广州网站优化推广方案
  • 温州高端网站建设百度网址链接是多少
  • 创建网站免费注册淘宝付费推广有几种方式
  • 广州有几个区几个县级市做seo前景怎么样
  • 西宁网络公司做网站哪家好买了500元黑科技引流靠谱吗
  • 网站动图怎么做的网站的优化
  • dw做网站字体 别人 电脑电商从零基础怎么学
  • wordpress 扫码支付宝seo关键词优化推广哪家好
  • 电子兼职网站建设网站建设推广多少钱
  • better wordpress minify长沙弧度seo
  • 黑客网站怎么做做好网络推广
  • 登录自己网站的后台 wordpress市场营销的八个理论
  • 钓鱼网站下载惠州网站建设
  • 电脑端网站和手机网站区别免费网站模板
  • 做视频网站视频用什么插件获客引流100种方法
  • 做网站 人员ip域名解析查询
  • 网站如何做优化排名怎么创建自己的免费网址
  • 重庆网站建设changeke网络营销方式对比分析
  • 锦州网站建设市场重大新闻事件
  • 管理咨询公司是做什么宁波网络推广优化方案
  • 什么网站做优化最好?企业网站制作哪家好