🔒 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
  • 314
    Views
  • 2
    Participants
Last reply from:
pixkit

Trending Topics

Online now

Members online
1,306
Guests online
3,622
Total visitors
4,928

Forum statistics

Threads
2,306,906
Posts
29,175,059
Members
1,194,087
Latest member
nanahnah
Back
Top