Alexis Alexis - 1 month ago 6
Ajax Question

calling a a div from another to current page through ajax call

I am calling html of div from another page to the page I am currently on. This is the script I am using

<script>
$(document).ready(function($))
{
$('#add').click(
function()
{
$.ajax(
{
url: 'addproducts.php',
success: function(data)
{
data=$(data).find('div#addproduct');
$('#divTransactional').html(data);
alert('Done.');
}
});
//$('#divTransactional').load('addproducts.php #addproducts');
})
}
</script>


And html

<a href="#" id="add">Add Products</a>
<div class="container" id="divTransactional"></div>


And here is addproduct.php

<div id="addproduct">
<form>
<div class="product-form">
<p class="text-product"></p>
<div>
<a class="add-product" href="#">Add Product</a>
</div>
</div>
<div>
<input type="submit" name="submitDetails" value="Finish"/>
</div>

</form>
</div>


Nothing happens. I guess there is something wrong with the script jquery.

Answer
$(document).ready(function($)
{
    $('#add').click(
    function()
    {
        $.ajax(
        {
            url: 'addproducts.php',
            success: function(data) 
            {
                data=$(data).find('div#addproduct');
                $('#divTransactional').html(data);
                alert('Done.');
            }
        });
        //$('#divTransactional').load('addproducts.php #addproducts');
    })
});