🔒 Closed Paano mag display ng value mula sa AJAX papunta sa alert(); (MVC5 C#)

Status
Not open for further replies.

1nn0c3ntv5

Fanatic
Gumawa ako ng IDataProvider interface, DataProviderInterface, DataGetController, at may view ako na Accounts.cshtml

IDataProvider Syntax:

public interface IDataProvider
{
List<Volunteer> GetVolunteer();
}

DataProvider Syntax:

public class DataProvider : DataAccess, IDataProvider
{
public List<Volunteer> GetVolunteer()
{
var result = new List<Volunteer>();
using (IDbConnection con = new SqlConnection(constring))
{
con.Open();
result = con.Query<Volunteer>(
StoredProcedureEnum.V_Volunteer.ToString(), commandType: CommandType.StoredProcedure).ToList();
}
return result;
}
}

DataGetController Syntax:

public class DataGetController : Controller
{
IDataProvider _IDataProvider;
public DataGetController()
{
_IDataProvider = new DataProvider();
}

public JsonResult GetVolunteer()
{
var data = _IDataProvider.GetVolunteer();
return Json(data, JsonRequestBehavior.AllowGet);
}
}

Ito yung problema ayaw niya mag display sa view:

Accounts.cshtml
<script>
$(document).ready(function () {
LoadVolunteer();
LoadMyTrial();
});

function LoadMyTrial() {
//debugger;
var temp;
$.ajax({
type: "GET",
"url": "/DataGet/GetVolunteer",

contentType: "application/json;charset=utf-8",
dataType: "json",
success: function (result) {
//alert(JSON.stringify(result));
$.each(response, function () {
temp.append('VolunteerID');
});
},
error: function (response) {
// debugger;
alert('error');
}
});
alert(temp);
}
</script>

nag didisplay naman siya pag gumamit ako ng
alert(JSON.stringify(result));

pero pano kung gusto ko lang makuha ay yung VolunteerID nila?
 
Is your AJAX request able to make the backend call and receive the data? If yes, so the problem is just assigning the response to the alert function?
 
Status
Not open for further replies.

About this Thread

  • 2
    Replies
  • 298
    Views
  • 2
    Participants
Last reply from:
pixkit

Online now

Members online
969
Guests online
2,994
Total visitors
3,963

Forum statistics

Threads
2,276,141
Posts
28,967,846
Members
1,231,131
Latest member
Yrrojan
Back
Top