开发者

Jquery get image

I am using a form to submit details to a page which create an image, the form is submitted using Jquery so that the user does not have to leave the page. The send() function calls on the refresh() function to update the div where the image is placed into...

I am having an issue with one of the lines of code of my code and I don't know what to put to get it to work:

    function 开发者_StackOverflowrefresh()
{
    $(function () {
        var img = new Image();
        $(img).load(function () {
            //$(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
            $(this).hide();
            $('#loader').removeClass('loading').append(this);
            $(this).fadeIn();
        }).error(function () {
            // notify the user that the image could not be loaded
// The next line causes the error
       }).attr('src', "signatures/" +$("#username") "png");
    }); 

}

Any help would be appreciated.


you horgot the dot before the extention:

.attr('src', "signatures/" +$("#username") "png");

should be:

.attr('src', "signatures/" +$("#username") ".png");

if $("#username") is a value. you might need a .html() / .text or .val() ,...


looks like you need + $("#username").val() + ".png") instead of +$("#username") "png")

This assumes that username is an id of some sort of hidden input field. replace val() with something else accordingly.


}).attr('src', "signatures/" +$("#username") "png");

You are passing a dom object, $("#username"). If the 'username' element is a textbox, you can use:

$("#username").val() + ".png"

And if it is a div or some other type of container you can use:

$("#username").text() + ".png"


Try this

 function refresh()
{
    $(function () {
        var img = $("<img />").appendTo(document.body);
        $(img).load(function () {
            //$(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
            $(this).hide();
            $('#loader').removeClass('loading').append(this);
            $(this).fadeIn();
        }).error(function () {
            // notify the user that the image could not be loaded
// The next line causes the error
       }).attr('src', "signatures/" +$("#username")+ ".png");
    }); 

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜