0

I have AJAX cal to back end

Here is code on front-end:

<script>
$(document).ready(function() {
    $.ajax({
        url: '@Url.Action("Profile_Data", "Interwier")',
        contentType: 'application/json; charset=utf-8',
        type: 'GET',
        dataType: 'json',
        cache: false,
        processData: false,
        success: function(data) {
           alert(data);
            var question2 = data;
            for (var i = 0; i <= question2.length - 1; i++) {
                var videoHTML = '<div style="width:100%;overflow-y: scroll;background:white;height:60%;border-bottom:solid;border-color: #A9A9A9;">' + '<div style="float:left; width:50%;height:296px;border-right:solid;border-color: #A9A9A9;margin-bottom:10px;">' +
                    '<video  style="width:100%;height:290px; object-fit: contain;padding-right: 15px;padding-left:15px;" controls>';
                videoHTML += '<source src="' + document.location.origin + "/uploads/" + question2[i].Linkes + ".webm" + '" type="video/webm">';
                videoHTML += '</video>' + '</div>' + '<div style="float:right;width:48%;text-align:center;height:296px;padding-top:30px;">' + '<div style="font-size:20px">' + '<b>' + question2[i].FIO + '</b>' + '</div>' + '<div style="font-size:20px">' + '<b>' + question2[i].City + '</b>' + '</div>' + '<div style="font-size:20px">' + '<b>' + (yyyy - question2[i].Vozrast) + '</b>' + '</div>' + '<div class="qustion-div-two" style="height:160px;margin-top:20px; background:white;" >' +
                    '<div id="comments" style="width: 100%; height: 70%;">' + '</div>' +
                    '<div id="write_field" style="width:100%;height:30%;font-size:15px;">' +
                    '<input type="text" "style="width:99%; height:75%;margin-left:2px;margin-bottom:5px;" />' + '</div>' + '</div>' + '</div>';
                $(".videolist").append(videoHTML);
            }
        }
    });
});

And here is code on back-end:

 public ActionResult Profile_Data()
    {
        var dataforprofile = TempData["FIO"];
        var profiledata = db.Link
            .Where(x => x.Interwier.FIO == dataforprofile)
            .Select(x => new
            {
                ID = x.Link_Id,
                Linkes = x.Link1,
                FIO = x.Interwier.FIO,
                City = x.Interwier.City,
                English_level = x.Interwier.English,
                Vozrast = x.Interwier.Birthday
            })
            .ToList();
        return Json(profiledata, JsonRequestBehavior.AllowGet);
    }

Script is working but I get this when call alert

enter image description here

Where is my problem?

Thank's for help.

1
  • 2
    Use console.log instead alert for objects. Commented May 16, 2017 at 9:35

2 Answers 2

2

It is actually JSON object, you will need to convert it to string for viewing string version in the alert which would be done using JSON.stringify() or you can console.log(data) to see the Json returned.

Try the following:

alert(JSON.stringify(data));

or see in console by logging it :

console.log(data);
Sign up to request clarification or add additional context in comments.

Comments

1

alert(data); data is collection of list, if you want to see object data value then you need to loop over the data

if(data!=null) {
$.each(data, function (i, data) {
           console.log(data)
        });
  }

contentType: 'application/json; charset=utf-8',

data type is json then you need to send data to server to be json format in your case should be empty data:{} 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.