gpt4 book ai didi

javascript - 抓取文本然后将该文本提交到特定路径

转载 作者:行者123 更新时间:2023-11-29 23:37:33 25 4
gpt4 key购买 nike

我想做的是抓取一个文本,然后将该文本提交到一个特定的应用程序路径,其中接受表单输入名称=“mykeyword”,我也希望在浏览器的新选项卡中打开它。

我做了一些练习,但没有运气。有什么想法吗?

    $("#ScanTitle").click(function () {
var mykeyword = $("#mykeyword").text();
// the 'mykeyword' variable will be submitted to 'Search/Index' route with INPUT name='mykeyword' form attribute in new window
$.post('Search/Index', function (data) {

var w = window.open('about:blank', 'windowname');
w.document.write(data);
w.document.close();
});

});
    <!DOCTYPE html>
<html>
<head>
<title>test</title>

<script
src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
crossorigin="anonymous"></script>

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

</head>
<body>

<button id="ScanTitle">button</button>
<p id="mykeyword">hand bags</p>



</body>
</html>

最佳答案

你需要给$.post提供参数:

$.post('Search/Index', {name: myKeyword}, function(data) {
var w = window.open('about:blank', 'windowname');
w.document.write(data);
w.document.close();
});

要绕过弹出窗口拦截器,您需要在点击处理程序中打开窗口,而不是 AJAX 回调。

$("#ScanTitle").click(function() {
var mykeyword = $("#mykeyword").text();
var w = window.open('about:blank', 'windowname');
$.post('Search/Index', {name: myKeyword}, function(data) {
w.document.write(data);
w.document.close();
});
});

关于javascript - 抓取文本然后将该文本提交到特定路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46009344/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com