pandiyan
5 months ago
10508
5
General

How to pass array from jquery ajax to php

Posted 5 months ago by pandiyan

hi i tried to pass array value from jquery to php using ajax post method but its not working.

the ajax code:

  QB['Title']=title;
  QB['Qtype']=Qtype;
  QB['Parrent']=Parrent;
  QB['Child']=Child;
  QB['options']=option;
     $.ajax({
              type:'post',
              async:false,
              url:'includes/feedback.php',
              data:{QB:QBarray,function:'Save_Question'},
              datatype:'json',
              beforesend:function()
              {
                    $(this).html('Please Wait...');
              },
              success:function(data)
              {
                 let json=JSON.parse(data)
                 toast_message(json.Result,json.Message);
              },
              error:function(data)
              {
                    console.log('Error');
              },
              complete:function()
              {
                    $(this).html('Submit');
              },

and PHP code is:

  elseif($_REQUEST['function']=='Save_Question')
  {
        // $QB_array[] = $_REQUEST['QB'];

        echo '<pre>';print_r(json_decode($_REQUEST['QB']));exit;

and got error like

Notice: Undefined index: QB in C:\xampp\htdocs\feedback\includes\feedback.php on line 33

Please sign in or create an account to participate in this conversation.