Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

post parameters #44

Open
aymenet1 opened this issue Apr 5, 2012 · 3 comments
Open

post parameters #44

aymenet1 opened this issue Apr 5, 2012 · 3 comments

Comments

@aymenet1
Copy link

aymenet1 commented Apr 5, 2012

I'm trying to post some parameters to be persisted in the database but they are not sent through the post method
adding
post :{
param1:'value1',
param2:'value2'
}
I can't get these parameter in the server side I don't know why can somebody help me please
thanks in advance

@ghost
Copy link

ghost commented Apr 8, 2012

Hey! I signed up on github just to help you, because I've been trying to figure out this thing for half a day! Anyway here you go, I hope I got your question right:

To send other values to that upload php you can use

data: {
 peter: 'griffin'
 glen: 'quagmire'
},

In php it will look like: $album = $_POST['peter'] and what you get from $album will be "griffin". So it's like when using "name" in submit form tag.

But it's not going to work with you jquery variables, it will show you an unexpected-blah-blah-error. So if you want to $_POST your variable you go like this:

var someValue = $("div").text();

data: {
 peter: function() {
   return someValue;
},

Here is my code, it can help:

var dropbox = $('#albumsstuff'),
          curAlbum = thisVal;

dropbox.filedrop({  
    fallback_id: 'upload_button',
    url: 'phps_portfolio/upload.php',
    paramname: 'imagefile',
    maxfiles: 5,
    maxfilesize: 30,

    data: {
        album: function() {
            return curAlbum;
        },
    },

    dragOver: function() {
        dropbox.addClass('dashedBorder');
    },

etc...

and PHP:

$filename = $_FILES['imagefile'];
$uploaddir = '../../images/';
$album = $_POST['album'];

$new_file_name = date("His").'_'.$filename['name'];

if(move_uploaded_file($filename['tmp_name'], $uploaddir.$album.'/'.$new_file_name))
{
    echo json_encode($new_file_name);
}

@chuja3
Copy link

chuja3 commented Aug 8, 2012

still get Notice: Undefined index: idItem .. ???

@marco-solare
Copy link

very cool, the construct

data: {
    variableName: function () { 
        return $('#identifier').value() 
    }
}

works perfect for me and saved my day!
Without it the user always got logged out the moment the picture was completely transmitted.

I had another version working previously where I just added the token manually like so:
url: '/articles/upload/authenticity_token=' + $('input[name=authenticity_token]').attr('value'),

however, this ceased to work, maybe due to some rails update.
My current rails Version according to my Gemfile is: 3.2.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants