当用户单击此按钮时,意味着要单击将更新数据库的void方法,因此我们知道已单击它。但是,每次单击该按钮时,它将使用户超链接到另一个页面(试图将用户带到asp-action)。我如何才能停止超链接?因此,当用户单击该按钮时,他们不会看到任何更改,但是会调用该方法。
<button type="button" asp-action="xxx" asp-controller="xxx" class="btn btn-primary">
答案 0 :(得分:0)
我认为您可能会把事情混在一起。
from __future__ import division, print_function, absolute_import
import tflearn
from tflearn.layers.core import input_data, dropout, fully_connected
from tflearn.layers.conv import conv_2d, max_pool_2d
from tflearn.layers.normalization import local_response_normalization
from tflearn.layers.estimator import regression
from data_utils import *
import os
from PIL import Image
from numpy import array
def res_image(f, image_shape=[224,224], grayscale=False, normalize=True):
img = load_image(f)
width, height = img.size
if width != image_shape[0] or height != image_shape[1]:
img = resize_image(img, image_shape[0], image_shape[1])
if grayscale:
img = convert_color(img, 'L')
elif img.mode == 'L':
img = convert_color(img, 'RGB')
img = pil_to_nparray(img)
if normalize: # << this here is what you need
img /= 255.
img = array(img).reshape(1, image_shape[0], image_shape[1], 3)
return img
# Building the network
network = input_data(shape=[None, 227, 227, 3])
network = conv_2d(network, 96, 11, strides=4, activation='relu')
network = max_pool_2d(network, 3, strides=2)
network = local_response_normalization(network)
network = conv_2d(network, 256, 5, activation='relu')
network = max_pool_2d(network, 3, strides=2)
network = local_response_normalization(network)
network = conv_2d(network, 384, 3, activation='relu')
network = conv_2d(network, 384, 3, activation='relu')
network = conv_2d(network, 256, 3, activation='relu')
network = max_pool_2d(network, 3, strides=2)
network = local_response_normalization(network)
network = fully_connected(network, 4096, activation='tanh')
network = dropout(network, 0.5)
network = fully_connected(network, 4096, activation='tanh')
network = dropout(network, 0.5)
network = fully_connected(network, 2, activation='softmax') # output is the number of outcomes
network = regression(network, optimizer='momentum',
loss='categorical_crossentropy',
learning_rate=0.001)
# Training
model = tflearn.DNN(network,
tensorboard_dir=R'C:\Users\b0588718\Source\Repos\AlexNet\AlexNet')
model.load('model.tfl')
f = r'C:\Users\b0588718\Source\Repos\AlexNet\AlexNet\rawdata\jpg\0\P1170047.jpg'
img = res_image(f, [227,227], grayscale=False, normalize=True)
pred = model.predict(img)
print(" %s" % pred[0])
标记不会重定向到任何地方,除非其类型为<button>
并且位于submit
标记内:
<form>
<form method="post" action="/foo">
<button type="submit">Send</button>
</form>
标签在使用正确的网址声明时将在点击时重定向:
<a>
可以使用Tag Helpers来构造:
<a href="/Home/Privacy">Privacy</a>
<a asp-controller="Home" asp-action="Privacy">Privacy</a>
标签和<button>
标签都不是自动关闭标签。此类标签需要使用结束标签关闭:
<a>
如果不重新加载没有用于处理请求发送的客户端脚本的页面,则将无法发送 HTTP GET 请求。当您单击页面上的链接时,浏览器将处理发送的请求,但这意味着页面重新加载(我在这里谈论的是纯HTML页面,没有SPA)。如果您不希望重新加载页面,则必须处理自己发送的请求。换句话说-从客户端脚本发送 HTTP 请求。
您可以使用<button type="button">Foo</button>
来实现:
jQuery
或纯JavaScript:
$('#updateDatabaseButton').click(function (e) {
$.get($(e.target).attr('formaction'), function (data) {
console.log(data);
});
});
最终,通过设置const updateButon = document.getElementById('updateDatabaseButton');
updateButon.onclick = function () {
var url = updateButon.getAttribute('formaction');
var http = new XMLHttpRequest();
http.open("GET", url);
http.send();
http.onreadystatechange = (e) => {
console.log(http.responseText)
}
};
将您的按钮链接到客户端脚本:
id