0

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
  • 2
    sigh Please, please, please when you get error messages, add that error message to your post. Commented Jul 22, 2010 at 15:58
  • 1
    Question title should probably read "$.post variable...", as "$post variable..." is likely to be misinterpreted in this case. Commented Jul 22, 2010 at 16:02
  • 1
    SQL injection alert! Commented Jul 22, 2010 at 17:06

2 Answers 2

3
    $.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);
    });
Sign up to request clarification or add additional context in comments.

4 Comments

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
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.
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!
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
3

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

excludes: {'contentType':['client','mainsetion']}   

3 Comments

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']}.
Why don't you edit your answer to make JS syntactically valid?
++ short and sweet and to the point. may not be enough for OP to chew though. cheers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.