Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Abhishek Bhardwaj
3,316 PointsJquery $.ajax not working
<form name="uploadp" id="uploadp" action="queries/basicintro.php" onsubmit="submitProfile(eve)" method="post" enctype="multipart/form-data" > <span class="fa fa-camera upload" id="uploadpic"></span> <input type="file" class="form-control opacity0" onchange="this.form.submit()" name="uploadprofile" id="uploadprofile"> <!-- <input type="submit" class="btn btn-success" id="button" name="btnform"> --> </form> <div id="msg"></div>
<script type="text/javascript">
function submitProfile(eprofile){
var uploadprofile = $('#uploadprofile').val();
eprofile.preventDefault();
console.log(uploadprofile);
$.ajax({
url: 'queries/basicintro.php',
type:'POST',
async:false,
data: {
'uploadprofile': uploadprofile,
},
success:function(ta){
$('#msg').html(ta);
}
});
alert('hii');
}
</script>

Abhishek Bhardwaj
3,316 PointsI made some changes but still its not working. please take a look again in code :)

Maximillian Fox
Courses Plus Student 9,236 PointsAdd some console.log() at various points of the function. Check which ones appear and which don't and use that as a basis to debug your code. Check whether all your variables are printing correctly, check there are no syntax errors as well to be sure.
Maximillian Fox
Courses Plus Student 9,236 PointsMaximillian Fox
Courses Plus Student 9,236 PointsJust looking at your function call - you have
<input type="file" class="form-control opacity0" onchange="submitProfile(this.form.submit())" name="uploadprofile" id="uploadprofile">
but then in your JS your function doesn't appear to input any arguments.
function submitProfile()
I see you call eprofile.preventDefault() - so should this be passed as an argument to then prevent the form submit event from reloading the page?
function submitProfile(eprofile)
I have never used AJAX but from a code POV, something seems off there. Maybe I'm wrong so not put this as an actual answer.