Hi all I am stuck trying to figure out the best way to get data as at the moment I have tried a few different ways to achieve this with no luck.

What I am trying to do is update a block of php code that is in my sidebar when I submit a button.

I have tried loading a file with ajax but because I am using the smarty template it loads the file but the
php code does not run.

I have managed to get it to work to a certain point but it has to refresh the page which is not what I am after
as firefox post a pop up alert saying the page needs reloading and also it resets the page that had previous data already loaded.

Does anyone know a better way to acheive this.

Recommended Answers

All 2 Replies

It might help to post some code, but the most likely reason is an error with the callback function in your ajax call.

The code I have so far submits to add a domian name to the cart which is on another page.

The problem is I am using Smarty Template and when the page I want the php code to update will not update unless I refresh the page.

And I cannot use ajax to request the page because I tried that and the php code did not run I just got a load of code that the Smarty template could not translate.

This bit of code gets an array from a session and echos the domain names added to cart.

{php} 
for ($i=0; $i<=10; $i++) {
$doms  = $_SESSION['cart']['domains'][$i]['domain'];
echo $doms, "<br />";
}
{/php} 

This code submits a domain name to add to the cart.

{literal}
<script type="text/javascript"> 
$(function(){
    $("#domainorder").submit(function(e){    
       e.preventDefault();
        $.post("cart.php?a=add&domain=register", $("#domainorder").serialize(),
        function(data){}, "json");  
                                }); 
                                return false;
    });
$(document).ajaxStop(function(){
    window.location.reload();
});
</script>
{/literal}

Once the above code runns it does the job but refreshes the page, idealy I need to not refresh the page but just the php code above all on the same page so it updates the domain names that are in the cart.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.