AJAX won't POST to PHP (Non jQuery) -


i've searched , search , find jquery questions , fixes this. have 1 script setup works fine 1 not post post 3 values php script. i've tried force feed 3 set values i'm putting timestamp , dosn't work. i'm @ bit of loss.

this script generates different fields/inputs run updatecoupon()

        function updateform(formnum,id){             var str = 'edit-contents'+id;             switch( formnum )             {                 case 1:                     document.getelementbyid(str).innerhtml = "<div class='title-input'>promo title:<br><input type='text' size='25' maxlength='100' id='ptitle' name='ptitle'><input name='edit' type='button' class='editcoup' id='editcoup' value='edit' onclick='javascript:updatecoupon("+id+",1);'></div>";                     break;                  case 2:                     document.getelementbyid(str).innerhtml = "<div class='description-input'>promo description:<br><textarea maxlength='1256' cols='40' rows='5' id='pdescription' placeholder='use <br> insert line break' name='pdescription'></textarea><input name='edit' type='button' class='editcoup' id='editcoup'  value='edit' onclick='javascript:updatecoupon("+id+",2);'></div>";                     break;                  case 3:                     document.getelementbyid(str).innerhtml = "<div class='disclaimer-input'>promo disclaimer:<br><textarea maxlength='1256' cols='40' rows='5' id='pdisclaimer' placeholder='use <br> insert line break' name='pdisclaimer'></textarea><input name='edit' type='button' class='editcoup' id='editcoup' value='edit' onclick='javascript:updatecoupon("+id+",3);'></div>";                     break;                  case 4:                     document.getelementbyid(str).innerhtml = "<div class='expdate'>promo experation:<br><input type='text' size='25' maxlength='100' id='datepicker'  placeholder='dd-mm-yyyy' name='datepicker'><input name='edit' type='button' class='editcoup' id='editcoup' value='edit' onclick='javascript:updatecoupon("+id+",4);'></div>";                     break;                  case 5:                     document.getelementbyid(str).innerhtml = "<div class='image-input'>select promo image:<br><select id='picture' name='picture'><option value='' selected>select image...</option><option value='http://cws.dealerconnection.com/images/max.png'>battery max</option><option value='http://cws.dealerconnection.com/images/plus.png'>battery max</option><option value='http://cws.dealerconnection.com/images/brake.gif'>brakes</option><option value='http://cws.dealerconnection.com/images/checkup.png'>check list</option><option value='http://cws.dealerconnection.com/images/creditcards.gif'>ford credit card</option><option value='http://cws.dealerconnection.com/images/lptg.png'>low price tire gaurentee</option><option value='http://cws.dealerconnection.com/images/michelin.gif'>michelin</option><option value='http://cws.dealerconnection.com/images/works.png'>the works</option><option value='http://cws.dealerconnection.com/images/4tires.gif'>tires</option><option value='http://cws.dealerconnection.com/images/tr99.png'>tire brand logos</option><option value='http://cws.dealerconnection.com/images/wipers.png'>wiper blades</option><option value='http://cws.dealerconnection.com/images/fpseal.png'>warranty ford parts</option><option value='http://cws.dealerconnection.com/images/mcseal.png'>warranty motocraft</option></select><input name='edit' type='button' class='editcoup' id='editcoup' value='edit' onclick='javascript:updatecoupon("+id+",5';'></div>";                     break;                  default:                     alert("error:"+formnum);                 break;             }         }         </script> 

ajax:

        var xmlhttp = '';          function createxmlhttprequest() {           if (window.activexobject) { xmlhttp = new activexobject("microsoft.xmlhttp"); }            else if (window.xmlhttprequest) { xmlhttp = new xmlhttprequest(); }         }          function updatecoupon(id,field)         {              var tempid = id;              switch( field )             {                 case '1':                     var updatefield = "headline";                     var title = form.ptitle.value;                     var querystr = "id=" + tempid + "&change=" + title + "&field=" +updatefield;                     break;                  case '2':                     var updatefield = "subhead";                     var desc = form.pdescription.value;                     var querystr = "id=" + tempid + "&change=" + desc + "&field=" +updatefield;                     break;                  case '3':                     var updatefield = "disclaimer";                     var disc = form.pdisclaimer.value;                     var querystr = "id=" + tempid + "&change=" + disc + "&field=" +updatefield;                     break;                  case '4':                     var updatefield = "couponexpires";                     var date = form.datepicker.value;                     var querystr = "id=" + tempid + "&change=" + date + "&field=" +updatefield;                     break;                  case '5':                                var updatefield = "graphics";                     var pic = form.picture.value;                     var querystr = "id=" + tempid + "&change=" + pic + "&field=" +updatefield;                     break;             }                  createxmlhttprequest();                var url = "/coupon_testing/ford_coupon_tool/php/couponedit.php?timestamp=" + new date().gettime();               xmlhttp.open("post", url, true);               xmlhttp.onreadystatechange = function () {                     if(xmlhttp.readystate == 4) {                     if(xmlhttp.status == 200) {                         var jresponse = xmlhttp.responsetext;                         if(jresponse != '')  {                             alert(jresponse);                         }                     }                   }                };                xmlhttp.setrequestheader("content-type", "application/x-www-form-urlencoded");                  xmlhttp.send(querystr);         } 

php:

        <?php             $ret = "error";             $id = $_post['id'];             $change = trim($_post['change']);             $field = trim($_post['field']);              include 'configuration.inc.php';             include 'connection.inc.php';             include 'db_functions.inc.php';         //set variables coupon setup form              if( $id != '' && $change != '' && $field != '' )             {                 //saving coupon database.                 $sql = "update ford_coupons set " . $field . "='" . addslashes($change)."' id='".addslashes($id)."' limit 1";                 execute_query($sql);                 $ret = $field." has been updated!";             }             // print $ret;             $str = "id=".$id.", change=".$change.", field=".$field;             print $str;         ?> 

can tell me issue here? been racking brain , of programmer friend , neither of know why not posting. thanks

you're calling updatecoupon(id,field) using numeric values, this

javascript:updatecoupon("+id+",1); 

but in switch statement, you're checking string values,

case '1': 

you need either call functions using string 'field' argument, or change cases use integers.

during execution, none of switch statements hit, hence empty ajax request...


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -