What is the point of that alert()
call? And what are you trying to do with the src
attribute? jQuery(selector).src doesn't do anything because you can't access the img
element or its attributes that way.
If you want the value of src
, then use:
var imgSrc = $('#pic').attr('src');
// or
var obj = {
'name' : 'pic',
'value' : $('#pic').attr('src');
};
I'm not sure how you plan on performing a file upload this way, but that's how you would do it. Still, I would suggest skimming the jQuery documentation to make sure you understand the basics on jQuery DOM manipulation. You always use .attr()
to get or set element attributes on a jQuery result. If you want to access actual element object or its properties, you need to use:
var elPic = $('#pic')[0];
// or
var imgSrc = $('#pic')[0].src;
Also, there's usually no point in mixing ID selectors with class selectors since IDs should be unique.
Lastly, I assume ".attr(src)
" was a typo in your code, but if it wasn't then you need to brush up on your JavaScript so that you know the difference between a variable and a string literal. String literals need to be enclosed in either single or double quotes, otherwise JavaScript thinks you're passing the function a variable named src
rather than the string "src".