0

Helloo.. I am stucked in a very difficult situation. I am implementing ajax in magento, but it is not working. Whenever I use that code in home page it run properly but the html is not added to the select box.Same is if run in another page, run properly I knw there are some issues in my home page But I am unable to get those, as there are no errors in console Please guide or suggest me something This is my ajax code

function getMake(country)
    {
        jQuery(".spinner").css("display", "block");
       var strUser = country;
        jQuery.ajax({
            type: "GET",
            dataType: "html",
            url: "productlist/index/getMake/", 
            data: {
                country: strUser},
            success: function(data)
            {
                jQuery(".spinner").css("display", "none");
                 jQuery("#selectbox1" ).html( data );
                //document.getElementById("selectbox1").innerHTML = data;
            }
        });
        return false;
    }

I had even used js / jquery but nothing is working. Please help

1

A very common error is to find duplicates ids in the DOM maybe you have 2 selectbox1 elements in the home page, so try to execute jQuery("#selectbox1") in your browser console and check if you have more than 1 objects match.

Check if your js block is executed and also check if XHR response is OK, ie:

...
success: function(data)
{
     ...
     console.log(data);
     ...
}
...
  • Thanx for the response Console show my data, actually data is fetching but the thing is it is not added to selec box.I also checked jQuery("#selectbox1") and it replies a single element – Vivek Khandelwal Dec 26 '15 at 5:57
  • Ok so try to replace: jQuery("#selectbox1").html(data) for: jQuery("#selectbox1").empty().append(data);-- (i always preffer this approach because i'm just a little paranoid -- – MauroNigrele Dec 26 '15 at 6:07
  • Boy I just say I love you – Vivek Khandelwal Dec 26 '15 at 6:08
  • oh one more thing, are you executing this code after the DOM is ready? – MauroNigrele Dec 26 '15 at 6:09
  • You make my day I was suffering from this from last 5 days and now I resolved it it was because of two same id only I now changed all the ids related to it and now it is working fine Thanx a ton mann – Vivek Khandelwal Dec 26 '15 at 6:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.