英文:
AJAX WITH JQUERY ON C# ASP.NET Core 6 MVC
问题
这是代码的翻译部分:
<script>
$(function(){
var url = '/Propiedades/Verificar';
var correo = $('#correo')
var data = {correoPropietario: correo}
$.post(url, data, function(data){})
})
</script>
英文:
I'm loading the information from a SQL database and I have a stored procedure, so I need a method to load.
This is my controller
[HttpPost]
public IActionResult Verificar(string correoPropietario)
{
var verificarCorreo = _PropiedadesData.Verificar(correoPropietario);
return Json(verificarCorreo);
}
How can I get back from the AJAX?
This is my AJAX call:
<script>
$(function(){
var url = '/Propiedades/Verificar';
var correo = $('#correo')
var data = {correoPropietario: correo}
$.post(url,data).donde(function(data){})
})
</script>
答案1
得分: 0
您可以向您的控制器发送请求,然后可以读取控制器返回的响应。
我已经检查了您的Ajax代码片段,并发现了一个问题,您在其中使用了$.post(url,data).donde(function(data){})
,这是不正确的。
在Ajax中,没有名为donde
的东西,我认为这是一个拼写错误。正确的方式应该如下:
Ajax请求格式:
HTML:
<strong><span id="appendHere"></span></strong>
<hr />
<button type="button" name="submitButton" value="Edit" class="btn btn-primary form-control"
onclick="GetAjaxResponse()">
提交请求
</button>
Javascript:
@section scripts {
<script>
function GetAjaxResponse() {
var url = 'http://localhost:5094/YourController Name/Verificar';
var correo = "Kiron";
$.post(url, { correoPropietario: correo }, function (result) {
alert("响应");
console.log(result);
$("#appendHere").html(result);
});
}
</script>
}
注意: 这里需要记住的一点是,您需要读取function(result)
,在这里您将获得控制器的响应数据。
输出:
注意: 如果您想了解更多详细信息,可以在此处查看更多示例。
英文:
> how can I get back from the AJAX, this is my AJAX
You could send request to your contrroller and then can read the response what your controller returns.
I have checked your ajax code snippet and found a issue where you have used $.post(url,data).donde(function(data){})
which is incorrect.
In ajax nothing as donde
which I am assuming a typos. The correct way you could refer as following:
Ajax Request Format:
HTML:
<strong><span id="appendHere"></span></strong></>
<hr />
<button type="button" name="submitButton" value="Edit" class="btn btn-primary form-control"
onclick="GetAjaxResponse()">
Submit Request
</button>
Javascript:
@section scripts {
<script>
function GetAjaxResponse() {
var url = 'http://localhost:5094/YourController Name/Verificar';
var correo = "Kiron";
$.post(url, { correoPropietario: correo }, function (result) {
alert("Response");
console.log(result);
$("#appendHere").html(result);
});
}
</script>
}
Note: Point you should remember here, you would need to read function(result) where you will get your controller response data.
Output:
Note: If you would like to know more details on it you could check more sample here.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论