2015-10-02 44 views
-2

Ajax調用 - 我需要一個Ajax調用,將表中的數據發送到我的PHP查詢

$client_number = $_POST['client_number']; 
 
\t $client_name = $_POST['client_name']; 
 
\t $service = $_POST['service']; 
 
\t $size = $_POST['size']; 
 
\t $volume = $_POST['volume']; 
 
\t $deliver_point = $_POST['deliver_point']; 
 
\t $port_orgin = $_POST['port_orgin']; 
 
\t $a_port_orgin = $_POST['a_port_orgin']; 
 
\t $road_freight = $_POST['road_freight']; 
 
\t $terms = $_POST['terms']; 
 
\t $competitor = $_POST['competitor']; 
 
\t $freight_speed = $_POST['freight_speed']; 
 
\t $report_comments = $_POST['report_comments']; 
 
\t $company_stage = $_POST['company_stage']; 
 
\t $meeting_rating = $_POST['meeting_rating']; 
 
\t $client_user_name = $_POST['client_user_name']; 
 
\t $client_user_status = $_POST['client_user_status']; 
 
\t $client_user_kids = $_POST['client_user_kids']; 
 
\t $client_user_hobbies = $_POST['client_user_hobbies']; 
 
\t $client_user_comments = $_POST['client_user_comments']; 
 

 
\t 
 
\t \t \t \t \t \t 
 
\t $query="INSERT INTO tobytemp.fcl_reports (client_number,client_name,service,size,volume,deliver_point,port_orgin,a_port_orgin,road_freight,terms,competitor,freight_speed,report_comments,company_stage,meeting_rating,client_user_name,client_user_status,client_user_kids,client_user_hobbies,client_user_comments) 
 

 
\t VALUES ('".$client_number."', '".$client_name."', '".$service."', '".$size."', '".$volume."', '".$deliver_point."', '".$port_orgin."', '".$a_port_orgin."', '".$road_freight."', '".$terms."', '".$competitor."', '".$freight_speed."', '".$report_comments."', '".$company_stage."', '".$meeting_rating."', '".$client_user_name."', '".$client_user_status."', '".$client_user_kids."', '".$client_user_hobbies."', '".$client_user_comments."');"; 
 
\t 
 
\t $result = $dbLink->query($query);

<!DOCTYPE HTML> 
 
<html> 
 
<head> 
 
<title>Sales App</title> 
 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
 
<meta name="keywords" content="" /> 
 
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> 
 
\t <link rel="shortcut icon" href="images/scicon.gif"/> 
 
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(
 
hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script> 
 
<link href='http://fonts.googleapis.com/css?family=Kreon:300,400,700' rel='stylesheet' type='text/css'> 
 
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" /> 
 
<!-- start plugins --> 
 
<script type="text/javascript" src="js/jquery.min.js"></script> 
 
<script src="https://code.jquery.com/jquery-1.10.2.js"></script> 
 
\t <script> 
 
\t \t $(function() { 
 
\t \t \t var pull \t \t = $('#pull'); 
 
\t \t \t \t menu \t \t = $('nav ul'); 
 
\t \t \t \t menuHeight \t = menu.height(); 
 
\t \t \t $(pull).on('click', function(e) { 
 
\t \t \t \t e.preventDefault(); 
 
\t \t \t \t menu.slideToggle(); 
 
\t \t \t }); 
 
\t \t \t $(window).resize(function(){ 
 
     \t \t var w = $(window).width(); 
 
     \t \t if(w > 320 && menu.is(':hidden')) { 
 
     \t \t \t menu.removeAttr('style'); 
 
     \t \t } 
 
    \t \t }); 
 
\t \t }); 
 
\t </script> 
 
\t 
 

 
\t 
 

 
<!----font-Awesome-----> 
 
    \t <link rel="stylesheet" href="fonts/css/font-awesome.min.css"> 
 
<!----font-Awesome-----> 
 
</head> 
 
<body> 
 
<div class="header_bg" id="home"><!-- start header --> 
 
<div class="container"> 
 
\t <div class="row header text-center specials"> 
 
\t \t <div class="h_logo"> 
 
\t \t \t <a href="index.html"><img src="images/logo.png" alt="" class="responsive"/></a> 
 
\t \t </div> 
 
\t \t <nav class="top-nav"> 
 
\t \t \t <ul class="top-nav nav_list"> 
 
\t \t \t \t <li><a href="fclclient.html">FCL Clients</a></li> 
 
\t \t \t \t <li class="page-scroll"><a href="rates.html">Rates</a></li> 
 
\t \t \t \t <li class="logo page-scroll"><a title="hexa" href="index.html"><img src="images/logo.png" alt="" class="responsive"/></a></li> 
 
\t \t \t <li class="page-scroll"><a href="clientreports.html">Reports</a></li> 
 
\t \t \t \t <li class="page-scroll"><a href="#contact">Contact</a></li> 
 
\t \t \t </ul> 
 
\t \t \t <a href="#" id="pull"></a> 
 
\t \t </nav> 
 
\t \t <div class="clear"></div> 
 
\t </div> 
 
</div> 
 
</div> 
 

 

 

 
<div class="main_bg" id="about"><!-- start about us --> 
 
<div class="container"> 
 
\t <div class="row about"> 
 
\t \t <div class="col-md-3 about_img"> 
 
\t \t \t <!--<img src="images/captain.png" alt="" class="responsive"/>--> 
 
\t \t </div> 
 
\t \t <div class="col-md-9 about_text"> 
 
\t \t 
 
\t \t 
 
\t \t \t </br></br><h3>Client Reports</h3> 
 
\t \t \t <h4>FCL Profile Extras</h4></br> 
 
\t \t \t <button class="buttons" id="showr">Show Table</button></br><button class="buttons" id="hider">Hide Table</button> 
 
\t \t \t </br></br> 
 
\t \t \t 
 
\t \t \t \t \t \t \t \t 
 
<script> 
 

 
$("#showr").click(function() { 
 
    $("#fcl_form_data-table").slideDown(100); 
 
}); 
 

 
$("#hider").click(function() { 
 
    $("#fcl_form_data-table").slideUp(100); 
 
}); 
 
</script> 
 
\t \t \t 
 
\t \t \t 
 
\t \t \t 
 

 
\t \t \t <table id="fcl_form_data-table" style="display: none"> 
 
\t \t \t <th>BROSWER DB ID</th> 
 
\t \t \t <th>client_number</th> 
 
\t \t \t <th>client_name</th> 
 
\t \t \t <th>service</th> 
 
\t \t \t <th>size</th> 
 
\t \t \t <th>volume</th> 
 
\t \t \t <th>deliver_point</th> 
 
\t \t \t <th>port_orgin</th> 
 
\t \t \t <th>a_port_orgin</th> 
 
\t \t \t <th>road_freight</th> 
 
\t \t \t <th>terms</th> 
 
\t \t \t <th>competitor</th> 
 
\t \t \t <th>freight_speed</th> 
 
\t \t \t <th>company_stage</th> 
 
\t \t \t <th>meeting_rating</th> 
 
\t \t \t <th>client_user_name</th> 
 
\t \t \t <th>client_user_status</th> 
 
\t \t \t <th>client_user_kids</th> 
 
\t \t \t <th>client_user_hobbies</th> 
 
\t \t \t <th>client_user_comments</th> 
 
\t \t \t <th>Upload</th> 
 
\t \t \t \t \t \t \t 
 
\t \t \t 
 
\t \t \t 
 
\t \t \t 
 
\t \t \t <tr id="fcl_form_data-head"> 
 
\t \t \t 
 
\t \t \t <!-- Saved data will be put here :D --> 
 
\t \t \t 
 
\t \t \t </tr> 
 
\t \t \t </table> 
 
\t \t \t 
 
\t \t \t </br> 
 
\t \t \t 
 
\t \t <!-- start --> 
 
\t \t 
 
<div class="footer_bg"> 
 
<div class="container"> 
 
\t <div class="row footer"> 
 
\t \t <div class="col-md-8 contact_left"> 
 
\t \t 
 
\t \t \t <form id="fcl_form_data-form" > 
 
\t \t \t \t \t 
 
\t \t \t \t <div class = "qborder" style="bottom-margin:500px; width:95%;"> 
 
\t \t \t \t 
 
\t \t \t \t \t <h4>Client Info</h4></br> 
 
\t \t \t \t \t 
 
\t \t \t \t \t <input type="text" name="client_number" placeholder="Client Number" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Client Number';}"> 
 
\t \t \t \t \t 
 
\t \t \t \t \t <input type="text" name="client_name" placeholder="Client Name" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Client Name';}"> 
 
\t \t \t \t </div> 
 
\t \t \t \t 
 
\t \t \t <div class="multi-field-wrapper"> 
 
\t \t \t <div class="multi-fields"> 
 
\t \t \t \t <div class="multi-field"> 
 
\t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t <div class = "qborder" style="width:15%;"> 
 
\t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t \t <h4>Shipping Info</h4></br> 
 

 
\t \t \t \t \t \t \t \t <select name='service'> 
 
\t \t \t \t \t \t \t \t <option value=''>Service - </option> 
 
\t \t \t \t \t \t \t \t <option value='Inport'>Inport</option> 
 
\t \t \t \t \t \t \t \t <option value='Export'>Export</option> 
 
\t \t \t \t \t \t \t \t <option value='Airfreight'>Airfreight</option> 
 
\t \t \t \t \t \t \t \t <option value='W/housing'>W/housing</option> 
 
\t \t \t \t \t \t \t \t </select> 
 
\t \t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t \t </br></br> 
 
\t \t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t \t <select name='size'> 
 
\t \t \t \t \t \t \t \t <option value=''>Size - </option> 
 
\t \t \t \t \t \t \t \t <option value='20'>20</option> 
 
\t \t \t \t \t \t \t \t <option value='40'>40</option> 
 
\t \t \t \t \t \t \t \t <option value='40'>40</option> 
 
\t \t \t \t \t \t \t \t <option value='HQ'>HQ</option> 
 
\t \t \t \t \t \t \t \t <option value='45'>45</option> 
 
\t \t \t \t \t \t \t \t <option value='LCL'>Exact</option> 
 
\t \t \t \t \t \t \t \t </select> 
 
\t \t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t \t </br></br> 
 
\t \t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t \t <select name='volume'> 
 
\t \t \t \t \t \t \t \t <option value=''>Volume - </option> 
 
\t \t \t \t \t \t \t \t <option value='Daily'>Daily</option> 
 
\t \t \t \t \t \t \t \t <option value='Weekly'>Weekly</option> 
 
\t \t \t \t \t \t \t \t <option value='Monthly'>Monthly</option> 
 
\t \t \t \t \t \t \t \t <option value='Yearly'>Yearly</option> 
 
\t \t \t \t \t \t \t \t <option value='Exact'>Exact</option> 
 
\t \t \t \t \t \t \t \t </select></br> 
 
\t \t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t \t <input type="text" name="deliver_point" placeholder="Deliver Point"> 
 
\t \t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t \t <input type="text" name="port_orgin" placeholder="Port Origin"> 
 
\t \t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t \t <input type="text" name="a_port_orgin" placeholder="A/Port Origin"> 
 
\t \t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t \t <input type="text" name="road_freight" placeholder="Road Freight"> 
 
\t \t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t \t <!-- onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Road Freight';}" --> 
 
\t \t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t \t <select name='terms'> 
 
\t \t \t \t \t \t \t \t <option value=''>Terms - </option> 
 
\t \t \t \t \t \t \t \t <option value='EXM'>EXM</option> 
 
\t \t \t \t \t \t \t \t <option value='FOB'>FOB</option> 
 
\t \t \t \t \t \t \t \t <option value='PrePaid'>PrePaid</option> 
 
\t \t \t \t \t \t \t \t </select> 
 
\t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t \t </br></br> 
 
\t \t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t \t <select name='competitor'> 
 
\t \t \t \t \t \t \t \t <option value=''>Competitor - </option> 
 
\t \t \t \t \t \t \t \t <option value='1'>1</option> 
 
\t \t \t \t \t \t \t \t <option value='2'>2</option> 
 
\t \t \t \t \t \t \t \t <option value='3'>3</option> 
 
\t \t \t \t \t \t \t \t </select></br> 
 
\t \t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t \t <input type="text" name="freight_speed" placeholder="Freight Speed" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Freight Speed';}"> 
 
\t \t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t \t <textarea name="report_comments" placeholder="Comments" onfocus="if(this.value == 'Comments') this.value='';" onblur="if(this.value == '') this.value='Comments;"></textarea> 
 
\t \t \t \t \t \t \t 
 
\t \t \t \t \t \t <button type="button" class="remove-field">Remove</button> 
 
\t \t \t \t \t \t 
 
\t \t \t \t \t \t <button type="button" class="add-field">Add field</button> \t \t \t \t 
 
\t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t </div> \t \t 
 
\t \t \t \t \t \t \t \t </br> 
 
\t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t \t 
 
\t \t \t \t </div> \t 
 
\t \t \t </div> 
 
\t \t \t </div> 
 

 
\t \t \t \t 
 
\t \t \t \t <div class = "qborder" style="width:95%;"> 
 
\t \t \t \t \t <h4>Meeting Info</h4></br> \t \t \t 
 
\t \t \t \t \t <select name='company_stage' > 
 
\t \t \t \t \t <option value=''>Company Stage - </option> 
 
\t \t \t \t \t <option value='1'>1</option> 
 
\t \t \t \t \t <option value='2'>2</option> 
 
\t \t \t \t \t <option value='3'>3</option> 
 
\t \t \t \t \t <option value='4'>4</option> 
 
\t \t \t \t \t </select> 
 
\t \t \t \t \t 
 
\t \t \t \t \t 
 
\t \t \t \t \t \t <select name='meeting_rating'> 
 
\t \t \t \t \t <option value=''>Meeting Rating - </option> 
 
\t \t \t \t \t <option value='1'>1</option> 
 
\t \t \t \t \t <option value='2'>2</option> 
 
\t \t \t \t \t <option value='3'>3</option> 
 
\t \t \t \t \t <option value='4'>4</option> 
 
\t \t \t \t \t <option value='5'>5</option> 
 
\t \t \t \t \t </select> 
 
\t \t \t \t 
 
\t \t \t \t </div> 
 
\t \t \t \t 
 
\t \t \t \t \t </br> 
 

 
\t \t \t \t <div class = "qborder" style="width:95%;"> 
 
\t \t \t \t <h4> Personal Information </h4></br> 
 
\t \t \t \t 
 
\t \t \t \t \t <input type="text" name="client_user_name" placeholder="User Name" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Name';}"> 
 
\t \t \t \t \t 
 
\t \t \t \t \t <select name='client_user_name_status'> 
 
\t \t \t \t \t <option value=''>Status - </option> 
 
\t \t \t \t \t <option value='Single'>Single</option> 
 
\t \t \t \t \t <option value='Married'>Married</option> 
 
\t \t \t \t \t </select> 
 
\t \t \t \t \t 
 
\t \t \t \t \t <select name='client_user_name_kids'> 
 
\t \t \t \t \t <option value=''>Kids - </option> 
 
\t \t \t \t \t <option value='1'>1</option> 
 
\t \t \t \t \t <option value='2'>2</option> 
 
\t \t \t \t \t <option value='3'>3</option> 
 
\t \t \t \t \t <option value='4'>4</option> 
 
\t \t \t \t \t <option value='5'>5+</option> 
 
\t \t \t \t \t </select> 
 
\t \t \t \t \t 
 
\t \t \t \t \t <input type="text" name="client_user_name_hobbies" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Hobbies';}"> 
 
\t \t \t \t \t 
 
\t \t \t \t \t 
 
\t \t \t \t \t <textarea name="client_user_comments" placeholder="Comments" onfocus="if(this.value == 'Comments') this.value='';" onblur="if(this.value == '') this.value='Comments;"></textarea> 
 
\t \t \t \t </div> 
 
\t \t \t \t 
 
\t \t \t \t </br> 
 
\t \t \t \t <span class="pull-left"> 
 
\t \t \t \t 
 
\t \t \t \t 
 
\t \t \t \t 
 

 
\t \t \t \t 
 
\t \t \t \t \t 
 
\t \t \t \t <!-- <input type="button" id="fcl_form_data-op-discard" value="Discard" /> \t --> 
 
\t \t \t 
 
\t \t \t \t <input type="submit" id="fcl_form_data-op-save" value="Save" /> 
 
\t \t \t \t 
 
\t \t \t \t 
 

 
\t \t \t \t <input type="hidden" name="id_entry" value="0" /> 
 
\t \t \t \t 
 
\t \t \t \t 
 
\t \t \t \t 
 
\t \t \t \t 
 
\t \t \t \t 
 
\t \t \t \t </span> 
 
\t \t \t \t <div class="clear"></div> 
 
\t \t \t </form> 
 
\t \t </div> 
 
\t 
 
\t </div> 
 
</div> 
 
</div> 
 

 
\t <!-- End \t --> 
 
\t \t \t 
 
\t \t \t 
 
\t \t </div> 
 
\t </div> 
 
</div> 
 
</div> 
 

 

 

 

 
<div class="footer_bg" id="contact"><!-- start footer --> 
 
<div class="container"> 
 
\t <div class="row footer"> 
 
\t 
 

 

 
\t \t <div class="col-md-4 contact_right"> 
 
\t \t \t <!-- <p><span>About Us: </span> Established in 1998, The Cardinal Maritime Group is one of the fastest growing logistics service providers. </p> --> 
 
\t \t \t <ul class="list-unstyled address"> 
 
\t \t \t \t <li><i class="fa fa-envelope"></i><a href="mailto:[email protected]">[email protected]</a></li> 
 
\t \t \t \t <li><i class="fa fa-phone"></i><span>England Tel: +44 (0) 161 492 1778</span></li> 
 
\t \t \t \t <li><i class="fa fa-map-marker"></i><span>Cardinal Maritime Limited, Leestone Road, Sharston Industrial Estate, Manchester M22 4RB </span></li> 
 
\t \t \t </ul> 
 
\t \t </div> \t \t 
 
\t </div> 
 
</div> 
 
</div> 
 
<div class="footer1_bg"><!-- start footer1 --> 
 
\t <div class="container"> 
 
\t \t <div class="row footer"> 
 
\t \t \t <div class="copy text-center"> 
 
\t \t \t \t <p class="link"><span>&#169; Cardinalmaritime | <a href="http://www.cardinalmaritime.com/"> Cardinal Maritime</a></span></p> 
 
\t \t \t \t <a href="#home" id="toTop" style="display: block;"><span id="toTopHover" style="opacity: 1;"> </span></a> 
 
\t \t \t </div> 
 
\t \t </div> 
 
\t </div> 
 
</div> 
 

 
<script> 
 
\t \t $('.multi-field-wrapper').each(function() { 
 
\t \t \t var $wrapper = $('.multi-fields', this); 
 
\t \t \t $(".add-field", $(this)).click(function(e) { 
 
\t \t \t \t $('.multi-field:first-child', $wrapper).clone(true).appendTo($wrapper).find('input').val('').focus(); 
 
\t \t \t }); 
 
\t \t \t $('.multi-field .remove-field', $wrapper).click(function() { 
 
\t \t \t \t if ($('.multi-field', $wrapper).length > 1) 
 
\t \t \t \t \t $(this).parent('.multi-field').remove(); 
 
\t \t \t }); 
 
\t \t }); 
 
\t \t \t 
 
\t 
 
</script> 
 

 

 

 
<script> 
 

 
var fcl_form_data = { 
 
\t index: window.localStorage.getItem("fcl_form_data:index"), 
 
\t $table: document.getElementById("fcl_form_data-table"), 
 
\t $form: document.getElementById("fcl_form_data-form"), 
 
\t $button_save: document.getElementById("fcl_form_data-op-save"), 
 
\t $button_discard: document.getElementById("fcl_form_data-op-discard"), 
 
\t init: 
 
\t function() { 
 
\t \t \t // initialize storage index 
 
\t \t \t if (!fcl_form_data.index) { 
 
\t \t \t \t window.localStorage.setItem("fcl_form_data:index", fcl_form_data.index = 1); 
 
\t \t \t } 
 

 
\t \t // initialize form 
 
\t \t fcl_form_data.$form.reset(); 
 
\t \t 
 
\t \t /* 
 
\t \t fcl_form_data.$button_discard.addEventListener("click", function(event) { 
 
\t \t fcl_form_data.$form.reset(); 
 
\t \t fcl_form_data.$form.id_entry.value = 0; 
 
\t \t }, 
 
\t \t true); 
 
\t \t */ 
 
\t \t 
 
\t \t fcl_form_data.$form.addEventListener("submit", function(event) { 
 
\t \t var entry = { 
 
\t \t id: parseInt(this.id_entry.value), 
 
\t \t client_number:this.client_number.value, 
 
\t \t client_name:this.client_name.value, 
 
\t \t service:this.service.value, 
 
\t \t size:this.size.value, 
 
\t \t volume:this.volume.value, 
 
\t \t deliver_point:this.deliver_point.value, 
 
\t \t port_orgin:this.port_orgin.value, 
 
\t \t a_port_orgin:this.a_port_orgin.value, 
 
\t \t road_freight:this.road_freight.value, 
 
\t \t terms:this.terms.value, 
 
\t \t competitor:this.competitor.value, 
 
\t \t freight_speed:this.freight_speed.value, 
 
\t \t report_comments:this.report_comments.value, 
 
\t \t company_stage:this.company_stage.value, 
 
\t \t client_user_name:this.client_user_name.value, 
 
\t \t client_user_name_status:this.client_user_name_status.value, 
 
\t \t client_user_name_kids:this.client_user_name_kids.value, 
 
\t \t client_user_name_hobbies:this.client_user_name_hobbies.value, 
 
\t \t client_user_comments:this.client_user_comments.value 
 
\t \t }; 
 
\t \t 
 
\t \t if (entry.id == 0) { // add 
 
\t \t fcl_form_data.storeAdd(entry); 
 
\t \t // Adds data to table when pressed save - like a temp table above 
 
\t \t fcl_form_data.tableAdd(entry); 
 
\t \t } 
 
\t \t else { // edit 
 
\t \t fcl_form_data.storeEdit(entry); 
 
\t \t fcl_form_data.tableEdit(entry); 
 
\t \t } 
 
\t \t this.reset(); 
 
\t \t this.id_entry.value = 0; 
 
\t \t event.preventDefault(); 
 
\t \t }, 
 
\t \t true); 
 
\t \t 
 
\t \t ////////////////////////////////////////////////////////////////////////////////////////Load DB info into table 
 
\t \t 
 
\t \t if (window.localStorage.length - 1) { 
 
\t \t \t var data_list = [], i, key; 
 
\t \t \t 
 
\t \t \t for (i = 0; i < window.localStorage.length; i++) { 
 
\t \t \t \t key = window.localStorage.key(i); 
 
\t \t \t \t if (/fcl_form_data:\d+/.test(key)) { 
 
\t \t \t \t \t data_list.push(JSON.parse(window.localStorage.getItem(key))); 
 
\t \t \t \t } 
 
\t \t \t } 
 
\t \t \t if (data_list.length) { 
 
\t \t \t \t data_list 
 
\t \t \t \t .sort(
 
\t \t \t \t function(a, b) { 
 
\t \t \t \t return a.id < b.id ? -1 : (a.id > b.id ? 1 : 0); 
 
\t \t \t \t }) 
 
\t \t \t \t .forEach(fcl_form_data.tableAdd); 
 
\t \t \t } 
 
\t \t } 
 
\t \t 
 
\t \t ///////////////////////////////////////////////////////////////////////////////////// 
 
\t \t 
 
\t \t fcl_form_data.$table.addEventListener("click", function(event) { 
 
\t \t \t var op = event.target.getAttribute("data-op"); 
 
\t \t \t if (/edit|remove/.test(op)) { 
 
\t \t \t \t var entry = JSON.parse(window.localStorage.getItem("fcl_form_data:"+ event.target.getAttribute("data-id"))); 
 
\t \t \t \t \t \t 
 
\t \t \t \t 
 
\t \t \t \t 
 
\t \t \t \t if (op == "edit") { 
 
\t 
 
\t \t \t \t fcl_form_data.$form.client_number.value = entry.client_number; 
 
\t \t \t \t fcl_form_data.$form.client_name.value = entry.client_name; 
 
\t \t \t \t fcl_form_data.$form.service.value = entry.service; 
 
\t \t \t \t fcl_form_data.$form.size.value = entry.size; 
 
\t \t \t \t fcl_form_data.$form.volume.value = entry.volume; 
 
\t \t \t \t fcl_form_data.$form.deliver_point.value = entry.deliver_point; 
 
\t \t \t \t fcl_form_data.$form.port_orgin.value = entry.port_orgin; 
 
\t \t \t \t fcl_form_data.$form.a_port_orgin.value = entry.a_port_orgin; 
 
\t \t \t \t fcl_form_data.$form.road_freight.value = entry.road_freight; 
 
\t \t \t \t fcl_form_data.$form.terms.value = entry.terms; 
 
\t \t \t \t fcl_form_data.$form.competitor.value = entry.competitor; 
 
\t \t \t \t fcl_form_data.$form.freight_speed.value = entry.freight_speed; 
 
\t \t \t \t fcl_form_data.$form.report_comments.value = entry.report_comments; 
 
\t \t \t \t fcl_form_data.$form.company_stage.value = entry.company_stage; 
 
\t \t \t \t fcl_form_data.$form.meeting_rating.value = entry.meeting_rating; 
 
\t \t \t \t fcl_form_data.$form.client_user_name.value = entry.client_user_name; 
 
\t \t \t \t fcl_form_data.$form.client_user_name_status.value = entry.client_user_name_status; 
 
\t \t \t \t fcl_form_data.$form.client_user_name_kids.value = entry.client_user_name_kids; 
 
\t \t \t \t fcl_form_data.$form.client_user_name_hobbies.value = entry.client_user_name_hobbies; 
 
\t \t \t \t fcl_form_data.$form.client_user_comments.value = entry.client_user_comments; 
 
\t \t \t \t fcl_form_data.$form.id_entry.value = entry.id; 
 
\t \t \t \t } 
 
\t \t \t \t else if (op == "remove") { 
 
\t \t \t \t \t if (confirm('Are you sure you want to remove "'+ entry.client_number +' '+ entry.client_name +'" from your fcl_form_data?')) { 
 
\t \t \t \t \t fcl_form_data.storeRemove(entry); 
 
\t \t \t \t \t fcl_form_data.tableRemove(entry); 
 
\t \t \t \t \t } 
 
\t \t \t \t } 
 
\t \t \t \t event.preventDefault(); 
 
\t \t \t } 
 
\t \t }, 
 
\t \t true); 
 
\t }, 
 
\t storeAdd: 
 
\t function(entry) { 
 
\t \t entry.id = fcl_form_data.index; 
 
\t \t window.localStorage.setItem("fcl_form_data:index", ++fcl_form_data.index); 
 
\t \t window.localStorage.setItem("fcl_form_data:"+ entry.id, JSON.stringify(entry)); 
 
\t }, 
 
\t 
 
\t storeEdit: 
 
\t function(entry) { 
 
\t \t window.localStorage.setItem("fcl_form_data:"+ entry.id, JSON.stringify(entry)); 
 
\t }, 
 
\t 
 
\t storeRemove: 
 
\t function(entry) { 
 
\t \t window.localStorage.removeItem("fcl_form_data:"+ entry.id); 
 
\t }, 
 
\t 
 
\t tableAdd: 
 
\t function(entry) { 
 
\t var $tr = document.createElement("tr"), $td, key; 
 
\t 
 
\t \t for (key in entry) { 
 
\t \t \t if (entry.hasOwnProperty(key)) { 
 
\t \t \t $td = document.createElement("td"); 
 
\t \t \t $td.appendChild(document.createTextNode(entry[key])); 
 
\t \t \t $tr.appendChild($td); 
 
\t \t \t } 
 
\t \t } 
 
\t \t 
 
\t \t $td = document.createElement("td"); 
 
\t \t $td.innerHTML ='<a data-op="edit" data-id="'+ entry.id +'">Edit</a> | <a data-op="remove" data-id="'+ entry.id +'">Remove</a>'; 
 
\t \t $tr.appendChild($td); 
 
\t \t $tr.setAttribute("id", "entry-"+ entry.id); 
 
\t \t fcl_form_data.$table.appendChild($tr); 
 
\t }, 
 
\t tableEdit: 
 
\t function(entry) { 
 
\t \t var $tr = document.getElementById("entry-"+ entry.id), $td, key; 
 
\t \t $tr.innerHTML =""; 
 
\t \t 
 
\t \t for (key in entry) { 
 
\t \t \t if (entry.hasOwnProperty(key)) { 
 
\t \t \t $td = document.createElement("td"); 
 
\t \t \t $td.appendChild(document.createTextNode(entry[key])); 
 
\t \t \t $tr.appendChild($td); 
 
\t \t \t } 
 
\t \t } 
 
\t \t $td = document.createElement("td"); 
 
\t \t $td.innerHTML ='<a data-op="edit" data-id="'+ entry.id +'">Edit</a> | <a data-op="remove" data-id="'+ entry.id +'">Remove</a>'; 
 
\t \t $tr.appendChild($td); 
 
\t }, 
 
\t tableRemove: 
 
\t function(entry) { 
 
\t fcl_form_data.$table.removeChild(document.getElementById("entry-"+ entry.id)); 
 
\t } 
 
}; 
 
fcl_form_data.init(); 
 
</script> 
 

 

 
</body> 
 
</html>


這裏是我的完整劇本,這是我的完整的腳本,這是我的完整腳本,這是我的完整腳本,這是我的完整腳本,這是我的完整腳本,這是我的完整腳本,這是我的完整腳本,H ERE是我的完整劇本,這是我的完整劇本,這是我的完整劇本,這是我的完整劇本,這是我的完整劇本,這是我的完整劇本,這是我的完整劇本,這是我的完整劇本,這是我的完整劇本,這是我的完整劇本,這是我的完整劇本,這是我的完整劇本,這是我的完整劇本,

+0

你用ajax試過嗎? –

+0

顯示你的Javascript代碼。 – Buzinas

+0

你不喜歡錶格和普通帖子? –

回答

1

我建議你重新開始你的代碼,這樣你就能夠設計它更好,但只要它已經太大了,而我沒有足夠的時間,我會保持你的風格,並盡力幫助你:

首先,你需要知道你的PHP代碼將只處理INSERT報表,因此,你需要做的編輯(UPDATE語句)另一個代碼,併爲清除(DELETE聲明)。

你已經有一個storeAdd功能,所以我複製到創建databaseAdd一個:

databaseAdd: function(entry) { 
    ajax('http://cmlsys/toby/fcl_form_upload.php', null, 'POST', entry); 
}, 

然後,我們ajax幫手:

function ajax(url, callback, method, params) { 
    if (!method) method = 'GET'; 

    var xhr = new XMLHttpRequest(); 
    xhr.open(method, url); 

    if (callback) xhr.addEventListener('load', function() { 
    callback.call(this, xhr); 
    }); 

    if (params) { 
    params = Object.keys(params).map(function (key) { 
     return encodeURIComponent(key) + '=' + encodeURIComponent(params[key]); 
    }).join('&'); 
    xhr.send(params); 
    } 
    else { 
    xhr.send(); 
    }  
} 

所以你使用正確的下面storeAddtableAdd功能:

​​
+0

非常感謝您的幫助,是否可以添加一個按鈕,使其僅在單擊時運行Ajax?只是這樣他們才能查看/查看它在添加到mysql數據庫之前的表中的內容@buzinas – rapidwaters

+0

所以我不能有2個按鈕? 1保存到瀏覽器,1上傳(運行AJAX) – rapidwaters

+0

如果沒有互聯網連接,它將保存到瀏覽器而不是mysql數據庫。所以我需要一個提交按鈕,以便在連接重新建立時發送。 – rapidwaters

相關問題