Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

191
Views
Why am i receiving error 404 when fetching video data?

I'm trying to display the video which is in mp4 format of the code's folder. When i try to fetch the video by clicking on the button it shows an empty space but doesn't display the video.display of the output

The error i'm receiving from the console: GET http://127.0.0.1:8080/myapi/myapi1/undefined 404 (Not Found)

Below is the url to display the json data: http://localhost:8080/myapi/myapi1/user/1

The link above displays:

{"videoName":"video.mp4"}

The code to fetch the video and display using ajax:

$('#room1').on('click',function (e){
                    $.ajax({
                    
                    method: "GET",
                    cache: false,
                    dataType: "json",
                    url: "http://localhost:8080/myapi/myapi1/user/1",
                    success: function(data) {
                        var student = '';

                    // ITERATING THROUGH OBJECTS
                    $.each(data, function (key, value) {
                        
                        // DATA FROM JSON OBJECT
                        student += '<video height="603"';
                           
                        student += 'src="' + 
                            value.videoName + '" autoplay loop muted></video>';
                    });
                    
                   
                    $('#video').append(student);
                    },
                    error:function(exception){alert('Exeption:'+exception);}
                    })
                    e.preventDefault();
                });
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

So, The data you are fetching is in JSON ENCODED FORMAT. so you need to parse it to a JS Object. like this: data = JSON.parse(data) in your success function.

over 4 years ago · Santiago Trujillo Report

0

(1) Since you only have one data item returned, please change the success block from:

success: function(data) {
var student = '';

// ITERATING THROUGH OBJECTS
$.each(data, function (key, value) {
                        
// DATA FROM JSON OBJECT
student += '<video height="603"';
                           
student += 'src="' + 
value.videoName + '" autoplay loop muted></video>';
});
                    
$('#video').append(student);
},

to

success: function(data) {
var student = '';

                        
// DATA FROM JSON OBJECT
student += '<video height="603"';
                           
student += 'src="' + 
data.videoName + '" autoplay loop muted></video>';
                    
$('#video').append(student);
},

data.videoName is already the data (video filename) you need

(2) However, if you have multiple data, like the following:

[{"videoName":"video.mp4"}, {"videoName":"video1.mp4"}]

then you may use the following :

success: function(data) {
var student = '';

 for (var x = 0; x < data.length; x++) {   
                        
// DATA FROM JSON OBJECT
student += '<video height="603"';
                           
student += 'src="' + 
data[x].videoName + '" autoplay loop muted></video>';

}
                    
$('#video').append(student);
},

data[index].videoName will be the data (video file name) for each index

(3) If you still prefer to use key / value pairs, the correct syntax will be like:

 $.each(data, function (key, value) {
  alert(data[key].videoName);
})
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!