Ajax Form Submit

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Ajax Form Submit

    Whats Error Here
    Code:
            <div id="wrapper">
                <div id="message" style="display: none;">
                </div>
                <div id="waiting" style="display: none;">
                    Please wait<br />
                    <img src="http://coding-talk.com/f14/themes/ajax-loader.gif" title="Loader" alt="Loader" />
                </div>
    
    <h2>Add a site</h2>
    <div>
    <form action="" id="myForm" method="post">
    Site Name <input name="title" type="text" id="title" value="" size="25"/>
    Site Url <input name="url" type="text" id="link" size="25" value="http://"/>
    Ads Type:<input name="url" type="type" id="type">
                      <option value="1">Normal Ads</option>
                      <option value="2">Adult +18 Ads</option>
                      <option value="3">Both Ads</option>
          </select>
          <input type="submit" name="AddSite" value="Submit"   class="submit" />
    Ajax Processer
    Code:
    $(document).ready(function(){
       $('#submit').click(function() {
          
          $('#waiting').show(500);
          $('#myForm').hide(0);
          $('#message').hide(0);
    
    var url = $("#url").val();
    var title = $("#title").val();
    var type = $("#type").val();
    var postme = 'url='+url+'&title='+title+'&type='+type;
    $.ajax({
    type : 'POST',
    url : 'ajax_misc.php?type=addsite',
    dataType : 'json',
    data : 'postme',
             success : function(data){
                $('#waiting').hide(500);
                $('#message').removeClass().addClass((data.error === true) ? 'error' : 'success')
                   .text(data.msg).show(500);
                if (data.error === true)
                   $('#myForm').show(500);
             },
             error : function(XMLHttpRequest, textStatus, errorThrown) {
                $('#waiting').hide(500);
                $('#message').removeClass().addClass('error')
                   .text('There was an error.').show(500);
                $('#myForm').show(500);
             }
          });
          
          return false;
       });
    });
    and
    ajax_misc.php
    Code:
    <?php
    require_once("inc/functions.php");
    require_once("inc/config.php");
    session_start();
    if(!isset($_SESSION['member_id']) && !isset($_SESSION['fullname']))
    {
       session_destroy();
       header("location: /login.php?nolog");
       exit;
    }
    
    $idd=escp($_SESSION['member_id']);
    
    if($_GET['type']=="addsite"){
    $title = post('title'); 
    $link = post('url');
    $type = post('type');
    $d = date("F j, Y, g:i a");
    $key = gen_key(16);
    if($type==1){ $type=1; } else{
    $type=2; }
       if(strlen($title) > 35 && strlen($title) < 10)
       {
       $return['error'] = true;
       $return['msg'] = 'Title Can Be between 10-35 Characters';
       }
       elseif(strlen($link) > 65)
       {
       $return['error'] = true;
       $return['msg'] = 'Field Link Can not be 65 characters Long';
       }
       elseif(!empty($title) && !empty($link) && !empty($type))
       {
          mysql_query("INSERT INTO pubsite SET userid='$idd',title='$title', link='$link', adult='$type', akey='$key', approved='1'") or die(mysql_error());
          mysql_query("UPDATE publisher SET total_site=(total_site+1) WHERE id='$idd'");
       $return['error'] = false;
          $return['msg'] = "Publisher site created successfully!<br>";
       }
       else
       {
       $return['error'] = true;
          $return['msg'] = "Error found! Check the inputs!";
       }
    }
    echo json_encode($return);
    exit;
    }
    ?>
    Last edited by shushant; 15.02.12, 06:34.
Working...
X