1 回答
TA贡献1784条经验 获得超2个赞
您需要使用AJAX调用。我jQuery.ajax
在此示例代码中使用了方法。您还可以使用浏览器的fetch
API 或XMLHttpRequest
API。
$(function() {
$('#Search').on('submit', function() {
event.preventDefault();
var url = 'https://api.hackertarget.com/aslookup/';
var data = $('#Search').serialize();
$.ajax(url + '?' + data).then(function(data) {
$('.output').text(data);
});
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form method="get" id="Search">
<input type="hidden" name="sites" value="" />
<input type="hidden" name="k7" value="#ffffff" />
<input type="hidden" name="k8" value="#222222" />
<input type="hidden" name="k9" value="#00278e" />
<input type="hidden" name="kx" value="#20692b" />
<input type="hidden" name="kj" value="#fafafa" />
<input type="hidden" name="kt" value="p" />
<input type="text" name="q" placeholder="INFO" aria-label="Search" />
<button type="submit">Search</button>
</form>
<pre class="output"></pre>
TA贡献1810条经验 获得超4个赞
<form onsubmit="onsubmitForm(event)">
<input type="hidden" name="sites" value="" />
<input type="hidden" name="k7" value="#ffffff" />
<input type="hidden" name="k8" value="#222222" />
<input type="hidden" name="k9" value="#00278e" />
<input type="hidden" name="kx" value="#20692b" />
<input type="hidden" name="kj" value="#fafafa" />
<input type="hidden" name="kt" value="p" />
<input type="text" name="q" placeholder="INFO" aria-label="Search" />
<button type="submit">Search</button>
</form>
<script src="https://code.jquery.com/jquery-3.4.1.js"
integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU=" crossorigin="anonymous"></script>
<script>
function onsubmitForm(e) {
e.preventDefault();
var url = "https://api.hackertarget.com/aslookup?q="+$("input[name='q']").val();
$.ajax({
url: url,
method: "GET",
success: function (result) {
console.log(result);
}
});
}
</script>
- 1 回答
- 0 关注
- 87 浏览
添加回答
举报