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 關注
- 128 瀏覽
添加回答
舉報