$(".projectCall").on("click", function (e) { var project_pk = $(this).attr("id"); getProjData(project_pk) }); function getProjData(project_pk) { $.ajax({ type: 'GET', url: "/projects/", data: {"project_pk": project_pk}, success: function (response) { // if not valid user, alert the user var projectData = response['project'][0]; var beforeImage = response['before_image']; var afterImage = response['after_image']; var yearText = projectData['year']; var makeText = projectData.make; var modelText = projectData.model; $("#projectYear").html(yearText); $("#projectMake").html(makeText); $("#projectModel").html(modelText); $("#projectBefore").attr("src", beforeImage);; $("#projectAfter").attr("src", afterImage);; $('#projectModal').modal('toggle'); }, error: function (response) { console.log(response); } }); }