views:

47

answers:

2

hello - sending some data via post but want to send an array to but keep getting errors?

excludes is the array i'm trying to send.

        $.post("/youradmin_v2/scripts/php/process.php", { 
            funcName:'searchContent',
            table:'content', 
            fields:'title,contentID', 
            keyword:$(this).val(), 
            tag:'option',
            excludes: ['contentType'=>'client','contentType'=>'mainsetion']                 
            }, 
            function(data){
            $("#filterContentMenu").html(data);
        });

I can't seem to find the correct way to format the array for posting?

or to clarify what i want is to turn this into a php array like

$excludes=array('fieldA'=>'client','feildB'=>'mainsetion')   

to be used like

foreach($excludes as $value) {
        $toExclude .=" AND ".$value['name']."!='".$value['value']."' ".$value;
    }
+3  A: 

You seem to be using PHP-style notation to specify the array keys. Try

excludes: {'contentType':['client','mainsetion']}   
Pekka
You need to use curly braces for that, not square brackets. In JS, brackets are for arrays, not objects. Also note, you'll probably overwrite it with the second one; you might want it to be more along the lines of `excludes: {contentType: ['client', 'mainsetion']}`.
Michael Louis Thaler
@Michael well spotted.
Pekka
Why don't you edit your answer to make JS syntactically valid?
BalusC
++ short and sweet and to the point. may not be enough for OP to chew though. cheers.
Sky Sanders
+3  A: 
    $.post("/youradmin_v2/scripts/php/process.php", { 
         funcName:'searchContent',
         table:'content', 
         fields:'title,contentID', 
         keyword:'blah', 
         tag:'option',
         excludes: {contentType:'client',anotherContentType:'mainsetion'}              
        }, 
        function(data){
        $("#filterContentMenu").html(data);
    });
vinhboy
ok this array stops the error; {contentType:'client',anotherContentType:'mainsetion'} - thanks!but its not getting picked up the way i expected by the php file.basically i was trying to create a string for an sql query. ie "AND contentType!='client' AND contentType!='mainsection'"but what i'm getting is AND c!='c' AND m!='m'using php foreach($excludes as $value) { $toExclude .="AND ".$value['name']."!='".$value['value']."' "; }do you think what i'm doing is possible?! many thanks! Dan
daniel Crabbe
examine the post - it's "excludes[contentType]" etc... also you cannot use the key name "contentType" twice. I think you can also do something like this "excludes: {contentType:['client','section']}".. just do a print_r($_POST) in your php to find out what it comes through as.
vinhboy
thanks vinhboy - i think i'm giving up on this method then. I'll just use a string via jquery which i wasn't to keen on doing due to security concerns.so;excludes:"AND contentType!='client' AND contentType!='mainsection'"thanks for your responses!
daniel Crabbe
++ for attention to detail.
Sky Sanders
oh.. i am sad you wont be using it :(...excludes: {contentType:['client','section']}becomes$_POST['excludes']['contentType'] which is an array, so you can use in_array.anywho, goodluck
vinhboy