3

I get this response:

{"success":true,"errorCode":-1,"error":""}

No HTML inside the JSON, but the js say its entered:

uncaught exception: You're trying to decode an invalid JSON String: <pre>{"success":true,"errorCode":-1,"error":""}</pre>

The code: http://www.pasteall.org/30057/javascript

The issue has been fixed that so odd seem like when you upload a file the ExtJS submit can't handle the json response. If you make at html and convert violà you got at.

$this -> output -> set_content_type('text/html'); 

that all the problem

Bob Kaufman
  • 12,864
  • 16
  • 78
  • 107
Sivan Wolberg
  • 348
  • 2
  • 6
  • 18

4 Answers4

3

The behaviour you experienced is actually documented (quite well buried, though) in ExtJS API docs - see description of Ext.form.Basic.hasUpload() method.

In short, file uploads are not performed by typical Ajax XMLHttpRequests. It uses a hidden iframe element instead. As a result, to quote ExtJS documentation:

If the server is using JSON to send the return object, then the Content-Type header must be set to "text/html"...

Which is exactly how you seemed to eventually solve your problem - so, this explains why it indeed works. So it's "not a bug, but a feature". :-D

Tommi
  • 8,550
  • 5
  • 32
  • 51
  • +1, In IE11, returning app/json as response to file import, prompts you to save the JSON as a file. Setting to text/html makes Ext act's correctly. Both FF/Chrome don't care if it's app/json or text/html, they behave correct both ways. – Radu Maris Apr 07 '15 at 17:35
1

Command Ext.JSON.decode('{"success":true,"errorCode":-1,"error":""}'); should parse the JSON response just fine.

Are you sure the error is not exactly what it says - does your response include the <pre>...</pre> tags by accident?

Tommi
  • 8,550
  • 5
  • 32
  • 51
1

It's hard to analyze the problem without seeing the code, so if you can add your code piece of client side, it may help.

Anyway, it seems that the result is returned in html format, i.e. contains non json data. Check why tags are included inside the result.

Check also the configuration of your server's page - it should be configured properly so to return JSON format.

It also explains why your result status is success. it is because the call to server operation was succeeded, i.e. the result was return to client without any error.

Now, after the server returned results to client, the store tries to operate the resulted data, but without success since the content is not in JSON format.

sna19
  • 404
  • 5
  • 9
0

I have the same problem when I insert a file field. If you delete it, it works. The problem does not come from the response itself. You have to manage the upload file on the server side.

Between server and client, response is transformed from 'json' to an html response.

see Uploading images using Node.js, Express, and Mongoose

Community
  • 1
  • 1
Farandole
  • 539
  • 2
  • 8
  • 23