`类型不匹配' jquery.ajax回调中的错误

时间:2015-11-17 09:27:16

标签: jquery ajax callback

我有以下html布局:

<form action="" method="post" id="addnew_sub">
<input type="hidden" name="tgtid" value="item">
<input type="hidden" name="crit" value="">

<table>
<tbody>
<tr>
<td>Product Type: </td>
<td>
    <select name="type">
        <option>Tablet</option>
        <option>Capsule</option>
        <option>Syrup</option>
        <option>Suspension</option>
        <option>Cream</option>
        <option>Oinment</option>
        <option>Drop</option>
        <option>Sachet</option>
        <option>Suppository</option>
        <option>Injection</option>
        <option>Pfs</option>
        <option>Vial</option>
    </select>
</td>
</tr>

<tr>
<td>Product Unit: </td>
<td>
    <select name="unit">
        <option>Tabs</option>
        <option>Caps</option>
        <option>Phials</option>
        <option>Sachets</option>
        <option>Vials</option>
        <option>Tubes</option>
        <option>Packs</option>
        <option>Cycles</option>
    </select>
</td>
</tr>

<tr>
<td>Generic Name: </td>
<td><input type="text" name="generic" size="70" value=""></td>
</tr>

<tr>
<td>Strength: </td>
<td><input type="text" name="strength" size="5" value=""></td>
</tr>

<tr>
<td>Strength Unit: </td>
<td>
    <select name="sunit">
        <option>nil</option>
        <option>mg</option>
        <option>gm</option>
        <option>ml</option>
        <option>pc</option>
    </select>
</td>
</tr>

<tr>
<td></td>
<td><input type="submit" class="addnew_sub" value="submit" name="submit"></td>
</tr>
</tbody>
</table>
</form>
<div id="result"></div>

遵循ajax代码:

   var myClass = this.classList;
   if(myClass[1]=='addnew_sub'){
   var act = myClass[1];
   var tgtid = null;
   var formid = $(this).closest('form').attr('id');
    var frm = "#"+formid ;
    var data = $(frm).serializeArray();
    data.push({name:'action',value:act});
    data.push({name:'tgtid',value:tgtid});
    getdirData(data);
  }

function getdirData(data){
  $.ajax({
      url,
      data: data,
      type:"POST",
      dataType: "html",
      success: function(cbdata){
          $("#result").html(cbdata).show();
               }
  });
}

和处理php页面代码:

  extract($_POST);
  if($action=='addnew_sub'){
    echo 'Data received successfully<br />';
    foreach($_POST as $key=>$val){
      echo 'Key: '.$key.' Value: '.$val.'<br />';
    }
  }

,输出为:

Type not matched
Data received successfully
Key: tgtid Value: item
Key: crit Value: 
Key: type Value: Tablet
Key: unit Value: Tabs
Key: generic Value: This is my entered text
Key: strength Value: 2000
Key: sunit Value: mg
Key: action Value: addnew_sub

我无法找到原因&#39;类型不匹配&#39;正在上面的输出开始。如果我按serializeArray()排除表单数据,则输出正常。

您是否有任何想法,其中&#39; Type not mached&#39;?

0 个答案:

没有答案