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

vue dropzone send json data format is trouble #152

Closed
niusmake opened this issue Jul 25, 2017 · 6 comments
Closed

vue dropzone send json data format is trouble #152

niusmake opened this issue Jul 25, 2017 · 6 comments

Comments

@niusmake
Copy link

I use vdropzone-sending ,and use JSON.stringify, send to json data to php

but data become string, then php is can not load..

it is this string json

["[{"id":86,"tag":"bruce","tag_status":1},{"id":88,"tag":"gif","tag_status":1}]"]

                 <dropzone ref="addUpload" id="VueBanner" :url="url"
                    style="text-align:center"
                    v-on:vdropzone-error="showError"
                    v-on:vdropzone-sending="dropzoneSending"
                    v-on:vdropzone-success="showSuccess"
                    :auto-process-queue="false"
                    :max-number-of-files="1"
                    :thumbnail-width="300"
                    :maxFileSizeInMB="500"
                    >
                      <!-- csrf -->
                      <input type="hidden" name="_token":value="csrf">
                  </dropzone>
'dropzoneSending': function(file, xhr, formData){
         formData.append('data',JSON.stringify(this.value));
},

How can I do? Please tell me. Thanks

@rowanwins
Copy link
Owner

Hi @niusmake

So is the server receiving the data variable but you're just not sure what to do with it? If that's the case you probably need to decode your json string on the server using something like php's json_decode function.

If that's not it you might need to provide more information...

@niusmake
Copy link
Author

niusmake commented Jul 25, 2017

Thank your reply~! @rowanwins

I has try json_decode , but is error message..

json_decode() expects parameter 1 to be string, array given

I think put json data into html form input is not work..
Is there any other way to pass from js?

like this

                $.ajax({
                    url: url,
                    type: 'post',
                    data: this.value,
                })

@rowanwins
Copy link
Owner

I think the approach you are using in the browser is fine, I think you are just doing something wrong in your server php. Can you post a snippet from your php as to what you're doing?

@niusmake
Copy link
Author

niusmake commented Jul 25, 2017

@rowanwins
Hello, sorry late reply you
this is my php code (I use Laravel)

$data = $request->data;
$value = json_decode($data);

@rowanwins
Copy link
Owner

so the error you were getting said json_decode expects an string but you passed an array, are you sure you passed in a string?

Perhaps trying something like a gettype() to check what $data is

$data = $request->data;
echo gettype($data)

It may be that you need to do something like

$data = $request->data;
$value = json_decode($data[0]);

@niusmake
Copy link
Author

@rowanwins
oh! this is work!
you're so helpful . thanks a lot!!!

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

2 participants