Ajax - 注意:未定义的索引:*

时间:2014-12-30 13:43:52

标签: javascript php jquery ajax post

我在将信息发送到php时遇到问题。 帮助pls :)所有帖子变量上的这样一个错误

  

注意:未定义的索引:第46行的D:\ xampp \ htdocs \ wa \ plugins \ generator \ ini.php中的Inn

JS:

function create_ini()
 {
 var ininame = document.getElementsByName('ininame')[0].value;
 var Inn = document.getElementsByName('Inn')[0].value;
 var SndrTel = document.getElementsByName('SndrTel')[0].value;
 var SendCtg = document.getElementsByName('SendCtg')[0].value;
 var SendDate = document.getElementsByName('SendDate')[0].value;
 var ListNum = document.getElementsByName('ListNum')[0].value;
 var MailType = document.getElementsByName('MailType')[0].value;
 var MailCtg = document.getElementsByName('MailCtg')[0].value;
 var DirectCtg = document.getElementsByName('DirectCtg')[0].value;
 var PayType = document.getElementsByName('PayType')[0].value;
 var TransType = document.getElementsByName('TransType')[0].value;
 var PostMark = document.getElementsByName('PostMark')[0].value;
 var MailRank = document.getElementsByName('MailRank')[0].value;
 var NumContract = document.getElementsByName('NumContract')[0].value;
 var MailCount = document.getElementsByName('MailCount')[0].value;
 var ValueSum = document.getElementsByName('ValueSum')[0].value;
 var DeliveryRateSum = document.getElementsByName('DeliveryRateSum')[0].value;
 var DeliveryRateVAT = document.getElementsByName('DeliveryRateVAT')[0].value;
 var DeliveryRateTotal = document.getElementsByName('DeliveryRateTotal')[0].value;
 var ValueSumRateTotal = document.getElementsByName('ValueSumRateTotal')[0].value;
 var ValueSumRateVAT = document.getElementsByName('ValueSumRateVAT')[0].value;
 var NoticeRateTotal = document.getElementsByName('NoticeRateTotal')[0].value;
 var NoticeRateVAT = document.getElementsByName('NoticeRateVAT')[0].value;
 var TotalRate = document.getElementsByName('TotalRate')[0].value;
 var TatalRateVAT = document.getElementsByName('TatalRateVAT')[0].value;
 var DocVersion = document.getElementsByName('DocVersion')[0].value;
 $.ajax({ 
  type: "POST",
  url:"ini.php",
  data: "Inn"+Inn+"SndrTel"+SndrTel+"SendCtg"+SendCtg+"SendDate"+SendDate+"ListNum"+ListNum+"MailType"+MailType+"MailCtg"+MailCtg+"DirectCtg"+DirectCtg+"PayType"+PayType+"TransType"+TransType+"PostMark"+PostMark+"MailRank"+MailRank+"NumContract"+NumContract+"MailCount"+MailCount+"ValueSum"+ValueSum+"DeliveryRateSum"+DeliveryRateSum+"DeliveryRateVAT"+DeliveryRateVAT+"DeliveryRateTotal"+DeliveryRateTotal+"ValueSumRateTotal"+ValueSumRateTotal+"ValueSumRateVAT"+ValueSumRateVAT+"NoticeRateTotal"+NoticeRateTotal+"     NoticeRateVAT"+NoticeRateVAT+"TotalRate"+TotalRate+"TatalRateVAT"+TatalRateVAT+"DocVersion"+DocVersio     n+"ininame"+ininame,
  success: function(data){
                         $("#mod-result").empty();
                         $("#mod-result").append(data);
                        /* location.reload(true); */
  }});
  };          

PHP:

$sampleData = array(
            'Main' => array(
                'Inn'     => $_POST['Inn'],
                'SndrTel' => $_POST['SndrTel'],
                'SendCtg' => $_POST['SendCtg'],
                'SendDate'  => $_POST['SendDate'],
                'ListNum'   => $_POST['ListNum'],
                'MailType'  => $_POST['MailType'],
                'MailCtg'   => $_POST['MailCtg'],
                'DirectCtg' => $_POST['DirectCtg'],
                'PayType'   => $_POST['PayType'],
                'TransType' => $_POST['TransType'],
                'PostMark'  => $_POST['PostMark'],
                'MailRank'  => $_POST['MailRank'],
                'NumContract'   => $_POST['NumContract'],
            ),
            'Summary' => array(
                'MailCount' => $_POST['MailCount'],
                'ValueSum'  => $_POST['ValueSum'],
                'DeliveryRateSum'   => $_POST['DeliveryRateSum'],
                'DeliveryRateVAT'   => $_POST['DeliveryRateVAT'],
                'DeliveryRateTotal' => $_POST['DeliveryRateTotal'],
                'ValueSumRateTotal' => $_POST['ValueSumRateTotal'],
                'ValueSumRateVAT'   => $_POST['ValueSumRateVAT'],
                'NoticeRateTotal'   => $_POST['NoticeRateTotal'],
                'NoticeRateVAT' => $_POST['NoticeRateVAT'],
                'TotalRate' => $_POST['TotalRate'],
                'TatalRateVAT'  => $_POST['TatalRateVAT'],
            ),
            'DocVersion' => array(
                'DocVersion'    => $_POST['DocVersion'],
            ));
write_ini_file($sampleData, $_POST['ininame'].'.ini', true);
echo $_POST['Inn'];

4 个答案:

答案 0 :(得分:3)

您收到该错误的原因是id,因为您的数据未正确发布。

data最好是一个对象,而不是像*那样的字符串。

替换:

data: "Inn"+Inn+"SndrTel"+SndrTel+"SendCtg"+SendCtg+"SendDate"+SendDate+"ListNum"+ListNum+"MailType"+MailType+"MailCtg"+MailCtg+"DirectCtg"+DirectCtg+"PayType"+PayType+"TransType"+TransType+"PostMark"+PostMark+"MailRank"+MailRank+"NumContract"+NumContract+"MailCount"+MailCount+"ValueSum"+ValueSum+"DeliveryRateSum"+DeliveryRateSum+"DeliveryRateVAT"+DeliveryRateVAT+"DeliveryRateTotal"+DeliveryRateTotal+"ValueSumRateTotal"+ValueSumRateTotal+"ValueSumRateVAT"+ValueSumRateVAT+"NoticeRateTotal"+NoticeRateTotal+"     NoticeRateVAT"+NoticeRateVAT+"TotalRate"+TotalRate+"TatalRateVAT"+TatalRateVAT+"DocVersion"+DocVersio     n+"ininame"+ininame,

使用:

data: {
    Inn: Inn,
    SndrTel: SndrTel,
    SendCtg: SendCtg,
    SendDate: SendDate,
    ListNum: ListNum,
    MailType: MailType,
    MailCtg: MailCtg,
    DirectCtg: DirectCtg,
    PayType: PayType,
    TransType: TransType,
    PostMark: PostMark,
    MailRank: MailRank,
    NumContract: NumContract,
    MailCount: MailCount,
    ValueSum: ValueSum,
    DeliveryRateSum: DeliveryRateSum,
    DeliveryRateVAT: DeliveryRateVAT,
    DeliveryRateTotal: DeliveryRateTotal,
    ValueSumRateTotal: ValueSumRateTotal,
    ValueSumRateVAT: ValueSumRateVAT,
    NoticeRateTotal: NoticeRateTotal,
    NoticeRateVAT: NoticeRateVAT,
    TotalRate: TotalRate,
    TatalRateVAT: TatalRateVAT,
    DocVersion: DocVersion,
    ininame: ininame
}

*使用"这样的字符串" ,我的意思是它的格式不正确。当然,a query string works, too.

答案 1 :(得分:1)

您的数据字符串不正确。它应该是:

data: {
    'Inn': Inn,
    'SndrTel': SndrTel,
    'SendCtg': SendCtg,
    'SendDate': SendDate,
    'ListNum': ListNum,
    'MailType': MailType,
    'MailCtg': MailCtg,
    'DirectCtg': DirectCtg,
    'PayType': PayType,
    'TransType': TransType,
    'PostMark': PostMark,
    'MailRank': MailRank,
    'NumContract': NumContract,
    'MailCount': MailCount,
    'ValueSum': ValueSum,
    'DeliveryRateSum': DeliveryRateSum,
    'DeliveryRateVAT': DeliveryRateVAT,
    'DeliveryRateTotal': DeliveryRateTotal,
    'ValueSumRateTotal': ValueSumRateTotal,
    'ValueSumRateVAT': ValueSumRateVAT,
    'NoticeRateTotal': NoticeRateTotal,
    'NoticeRateVAT': NoticeRateVAT,
    'TotalRate': TotalRate,
    'TatalRateVAT': TatalRateVAT,
    'DocVersion': DocVersion,
    'ininame': ininame
}

在您的情况下,数据变量将包含单个字符串。

答案 2 :(得分:1)

您的查询字符串格式错误。您需要使用=&在键和值之间分隔它们。 Inn=' + Inn + '&SndrTel='+SndrTel...

但最好的方法是,如果你发送$(form).serialize()

答案 3 :(得分:-2)

数据必须包含有效的查询字符串或对象。喜欢:

data : "Inn="+Inn+"&SndrTel="+SndrTel+....  

data : {  inn:inn, SndrTel:SndrTel....}