PDA

View Full Version : fileUpload problem



stratboogie
26 Mar 2011, 2:21 PM
Hello,
I am having a problem with the response having uploading a file. I have read through the docs and think i am doing everything right.

my form has:
fileUpload: true,
frame: true

I am getting the file and processing fine on my server. But when I output the response, which looks like this:
{data:null,success:true}

but it is breaking on this line in extjs-all:
doDecode=function(json){return eval("("+json+")")}

and here the json looks like this:
<PRE>{data:null,success:true}</PRE>

Am doing something else wrong? I have my ContentType set to "text/html".

here is by method that writes the response back out to the client:



Private Sub OutputJsonHTML(ByVal o As Object, ByVal Name As String, ByVal bSuccess As Boolean, ByVal nTotalCount As Int32)
Dim s As String = JSONHelper.Serialize(o)
Response.Clear()
Response.ContentType = "text/HTML; charset=utf-8"
Response.Write("{")
Response.Write(String.Format("{0}:{1}", Name, s))
If Not nTotalCount = -1 Then
Response.Write(String.Format(",count:{0}", nTotalCount))
End If
Response.Write(String.Format(",success:{0}", JSONHelper.Serialize(bSuccess)))
Response.Write("}")
If bSuccess Then
Response.StatusCode = 200
Else
Response.StatusCode = 400
End If
Response.Flush()
Response.End()
End Sub


tanks
Timothy

stratboogie
28 Mar 2011, 4:57 AM
Any Suggestions?

tvanzoelen
28 Mar 2011, 5:42 AM
Try responsetype

Response.ContentType = "text/javascript";

or

Response.ContentType = "application/x-javascript";

stratboogie
28 Mar 2011, 5:33 PM
I tried both and neither worked. im not sure what is going on. I am doing exactly what the documentation says to do with regarding file uploads. Any other suggestions?

jratcliff
28 Mar 2011, 8:31 PM
what happens if you drop "; charset=utf-8" from the ContentType?

stratboogie
29 Mar 2011, 3:06 AM
Yeah I have tried:

text/html,
text/HTML,
text/html; charset=utf8
text/javascript (this thread)
application/x-javascript

I have specified no contenttype with just a response of StatusCode = 200

Any more suggestions?

stratboogie
29 Mar 2011, 3:17 AM
I got it fixed. I had a typo in my server side code. I created some overloaded methods for outputting depending if I was doing a file upload or not. Needless to say, in one of my methods I was still calling my old output method that was responding with ContentType = "text/plain". Thanks for everyone's help

Timothy

senacle
9 Jan 2012, 12:55 AM
I was facing the same problem : the json response was not interpreted.

So, i do this :

htmlentities for the error message
header("Content-Type: text/html"); for the json response
Ext.util.Format.htmlDecode in the form

For example :
Error message (php)

$msgerror = utf8_encode(htmlentities($msgerror));
Json response (php)

header("Content-Type: text/html");
$array_error_variable = $validation['champ'];
$array_error_variable['message_erreur'] = $msgerror;
$jsonerror = json_encode($array_error_variable);
echo "{ success: false,
errors: ".$jsonerror."
}";

Form failure message (javascript)

var message = Ext.util.Format.htmlDecode(Ext.decode(action.response.responseText).errors.message_erreur);