【发布时间】:2021-07-30 15:29:19
【问题描述】:
我的脚本代码如下。在这里,如何保存我收到的 exits_response 数据作为对控制器中数据库的响应?在后操作结果中,参数“变量”为空。当 ajax 中没有邮政编码时,响应返回并显示“exist_response”。我没有写注册到控制器的过程,因为我在发布时得到了空数据。
我解决了问题,我错误地定义了数据变量。
js 代码
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js%22%3E</script>
<script type="text/javascript">
$('#submit').click(function (event) {
event.preventDefault();
var exist_response = $.ajax({ type: "GET", url: "https://heroku-diagnosis.herokuapp.com/predict", data: "Symptom_1=" + $('#Symptom_1').val() + "&Symptom_2=" + $('#Symptom_2').val() +
"&Symptom_3=" + $('#Symptom_3').val() + "&Symptom_4=" + $('#Symptom_4').val() + "&Symptom_5=" + $('#Symptom_5').val() + "&Symptom_6=" +
$('#Symptom_6').val() + "&Symptom_7=" + $('#Symptom_7').val() + "&Symptom_8=" + $('#Symptom_8').val() + "&Symptom_9=" + $('#Symptom_9').val() + "&Symptom_10=" + $('#Symptom_10').val() +
"&Symptom_11=" + $('#Symptom_11').val(),async: false}).responseText;
$('#output').text("According to the symptoms you have entered, you may have a " +exist_response + " disease. Make an appointment on our website to consult a doctor. " );
$.ajax({
type:"POST",
url:"/Prediction/Index",
data: { variable: exist_response },
success: function(response){
alert(response);
}});
</script>
控制器
[HttpPost]
public ActionResult Index(String variable,int id)
{
return View();
}
【问题讨论】:
-
这篇文章需要更多细节。
-
对不起,我看不出第一个 ajax 与第二个有什么关系?什么是输出?哪个 ajax 不能正常工作?
标签: c# json ajax asp.net-mvc