Forum Discussion
panos2024b
Oct 28, 2024Copper Contributor
ajax and connection to mvc .net
I need to access some c# code from javascript in MVC ,NET (not blazor). I have the below. This is very specific to .NET and MVC stack and not a generic ajax question like another one in stack overfow...
- Oct 31, 2024It worked by this async: false,. However async: = false, is deprecated apparently soon and needs the new way which i will investigate and change in my code
C#
public string CreateCoordinatesFromPostcode(string postcode)
{
string result = "XXXXXX" // your logic
return result;
}
JavaScript
let result = '';
$.ajax({
type: "POST",
url: '/clib/CreateCoordinatesFromPostcode',
async: false,
data: { postcode: postcode },
success: function (response) {
result = response;
},
error: function (error) {
console.error(error);
}
});
console.log("just after /clib/createCoordinatesFromPostcode");
return result;
panos2024b
Oct 31, 2024Copper Contributor
It worked by this async: false,. However async: = false, is deprecated apparently soon and needs the new way which i will investigate and change in my code
C#
public string CreateCoordinatesFromPostcode(string postcode)
{
string result = "XXXXXX" // your logic
return result;
}
JavaScript
let result = '';
$.ajax({
type: "POST",
url: '/clib/CreateCoordinatesFromPostcode',
async: false,
data: { postcode: postcode },
success: function (response) {
result = response;
},
error: function (error) {
console.error(error);
}
});
console.log("just after /clib/createCoordinatesFromPostcode");
return result;
C#
public string CreateCoordinatesFromPostcode(string postcode)
{
string result = "XXXXXX" // your logic
return result;
}
JavaScript
let result = '';
$.ajax({
type: "POST",
url: '/clib/CreateCoordinatesFromPostcode',
async: false,
data: { postcode: postcode },
success: function (response) {
result = response;
},
error: function (error) {
console.error(error);
}
});
console.log("just after /clib/createCoordinatesFromPostcode");
return result;