views:

58

answers:

3
+1  Q: 

JQuery issue by IE

I get an error by following code:

jQuery.post('/user/result/generate',{
            'id': getHidden()
        }, function(html) {
            $('#result').html(html);
        });

error:

TypeError object doesn't support this property or method

this code works fine in FireFox, but not in IE.

How can I fix this?

p.s

the function getHidden() wil return a selected item id, it works very fine. I can see that this work!

I put alert() in this function... like this:

jQuery.post('/user/result/generate',{
        'id': getHidden()
    }, function(html) {
        alert(html);
        $('#result').html(html);
    });

function getHidden(){
alert($("#selectId").val());
return $("#selectId").val();

}

and I get the selectId well! but not html, so this function stops by function(html), thus by the response! I put try catch in this function, get error: TypeError object doesn't support this property or method

but this function works fine after refresh the page by press F5.... so I do not understand why this function works not directly but after refresh...

A: 

What is "result" element ? It probably doesn't support .html() property, try .text() or .val()

Mahesh Velaga
What do you mean by "doesn't support"? jQuery methods can be used on any DOM element.
casablanca
@casablanca: To my knowledge on input elements you can't use .html()
Mahesh Velaga
input elements support html(). It return the empty string
tster
@tster: yes, but this is a call to *set* innerHTML. I think Mahesh is on the right track, but without clarification from Bili it's impossible to know.
Shog9
@Shog9, nevertheless, the html() function still exists (and works in my browser)
tster
@tster: try this, on this very page, if you're running IE... `$("#search input").html("blah")` - obviously html() itself exists, because it exists on all jQuery objects... but it's trying to use a property that (in IE at least) doesn't exist for input elements.
Shog9
@Shog9, `Unexpected call to method or property access.` != `TypeError object doesn't support this property or method`
tster
@tster: no... but then again we don't know what version of IE the OP is using, what element he's trying to access, or what sort of devious tricks getHidden() is up to. It's psychic debugging or nothing... A couple more hours without a response from Bili, and I'm voting to close this, but for now Mahesh is the only one to post a plausible answer.
Shog9
#result is an ID of div... i want to put the ajax result to the div #result.
Bili
A: 

Try putting getHidden in a var first.

var getId = getHidden();
jQuery.post('/user/result/generate',{
            'id': getId
        }, function(html) {
            $('#result').html(html);
        });
Detect
solved! I put the script bottom of html file, it works now both FF and IE.
Bili
+1  A: 

solved! I put the script bottom of html file, it works now both FF and IE.

Bili