views:

72

answers:

1

Hello,

I have a error when i tried to send post data with ajax() method.

I have a array with :

  • acpitool
  • aide

I use encodeURIComponent() for passing the array with data: but the ajax method fail.

Could you help me?
Thanks

Edit :

This is the ajax call

    $.ajax({
    url: 'AjaxSearch.php',
    dataType: 'json',
    data: param+"="+package,
    type: 'POST',
    success: function(data) {
    }
});

package is a Array like this :

var package = new array("acpitool","aide");

Sometimes, i have this :

var package = new array("bonnie++");

For both, i have an error :

Uncaught Syntax error, unrecognized expression: +

Thanks again!

+2  A: 
$.ajax({
   url: 'AjaxSearch.php',
   dataType: 'json',
   data: {
      param:  $.param(package);
   }
   type: 'POST',
   success: function(data) {
   }
});

use jQuerys .param() method to serialize an array.

Description: Create a serialized representation of an array or object, suitable for use in a URL query string or Ajax request.

update based on your comment, try this

data: {
      param:  package.join(',');
}
jAndy
Sorry, this is a edit error..the correct line is :data: param+"="+package,
Crupuk
param is the name of the variable like :?p=vari test your code,thanks
Crupuk
Crupuk
It work's !! Many thanks to all
Crupuk
jAndy