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

Trending Topics

Online now

Members online
1,008
Guests online
9,103
Total visitors
10,111

Forum statistics

Threads
2,354,344
Posts
29,383,327
Members
1,079,421
Latest member
Hashim27
Back
Top