Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2014
    Thanked 0 Times in 0 Posts

    Post How to load a website in the background using ajax

    Hey Guys,

    I'm quite experienced in PHP and MySQL however I've never looked at ajax before and I'm now struggling....

    I've got a url which can be processed via ajax however I cannot get it to process...

    <a href="https://mydomain.com/cart.php?ajax=1&a=add&domain=register&domains[]={$result.domain}&domainsregperiod[{$result.domain}]=1" /><img src="templates/dj/add.jpg" /></a>
    the {result.domain} is picked up via smarty on the page - when I put my mouse over my add to basket image the url shows correctly but clicking it does nothing...

    I've just got no idea where to start!

    Can anyone help me out please?

  2. #2
    New to the CF scene
    Join Date
    Jul 2014
    Thanked 0 Times in 0 Posts
    I've found a guide online for submitting a contact form (same idea really)

    I've now added:

    <script type="application/javascript">
    $(function() {
      $(".button").click(function() {
        // validate and process form here
        var name = $("input#domain").val();
          if (name == "") {
          return false;
    var dataString = 'domain='+ domain;
    //alert (dataString);return false;
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#add-form').html("<div id='message'></div>");
        $('#message').html("<h2>Added to Basket!</h2>")
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
    //return false;
    Then my actual form

    <form method="post" action="{$systemsslurl}cart.php?ajax=1&a=add&domain=register" name="add-form" id="add-form">
    <input type="hidden" name="domain" id="domain" value="{$result.domain}"/>
    <table width="700" border="0" cellspacing="5" cellpadding="0">
      {foreach from=$availabilityresults key=num item=result}
        <tr style="border-bottom: #333 1px solid;">
        <td rowspan="2">{if $result.status eq "available"}<img src="templates/dj/yes.jpg" />{else}<img src="templates/dj/no.jpg" />{/if}</td>
        {if $result.status eq "available"}<td style="color:#339933;" />{$result.domain|replace:$domain:''}</td>{else}<td style="color:#cc0000;" />{$result.domain|replace:$domain:''}</td>{/if}
        <td rowspan="2">{$result.domain}</td>
        <td rowspan="2">{if $result.status eq "unavailable"}<img src="templates/dj/transfer.jpg" />{else}<select name="domainsregperiod[{$result.domain}]">{foreach key=period item=regoption from=$result.regoptions}<option value="{$period}">{$period} {$LANG.orderyears} @ {$regoption.register}</option>{/foreach}</select>{/if}</td>
        <td rowspan="2">{if $result.status eq "available"}
        <div id="add-to-cart">
        <input type="image" src="templates/dj/add-basket.png" name="button" id="button" />
        <td>{if $result.status eq "available"}Available{else}Taken{/if}</td>
      <tr><td colspan="8" style="height:1px; background-color:#999;"></td></tr>
    However it just changes my page to cart.php - I'm lost lol

  3. #3
    Master Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Behind the Wall
    Thanked 567 Times in 560 Posts
    However it just changes my page to cart.php
    well of course, when you click on one of the image buttons (image buttons automatically submit the form) the form will load the URL listed in its action attribute.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts