Json of jquery form plugin cannot be acquired
I will upload the file by using jquery form plugin, and question on the phenomenon of process of $.ajaxForm becoming timeout when the response data is json.
Processing by the servers end is done without trouble, and the response data is returned in the shape along as long as it sees with firebug the json form. However, I think that $.ajaxForm cannot acquire data. Hereafter, it is a part of processed code.
code $('#upload').ajaxForm({ cache: false, dataType: 'json', type: 'POST', error:开发者_如何学运维 function(xhr ,status ,error ) { alert('error occured. Status:' + status + ' --Status Text:' + error + ' --Error Result:' + xhr.statusText); }, timeout: 1000, dataType:'json', data:{ 'path':'path' , 'type':'type' }, complete: function(){ alert('complete'); }, success:function(data){ alert('success'); }, });
response
(firebug)
header
Connection close
Content-Length 155
Content-Type application/json; charset=utf-8
Status 200
data
json
{"type":"json","message":"complete process"}
<i>(A browser)</i>
①download json data
②alert('error occured. Status:timeout --Status Text:timeout --Error Result:n/a')
③alert('complete')
</pre>
When dataType was html, success was able to be processed. Moreover, when it is $.ajax, json becomes success. Are there a settlement plan?It asks suitably.
try setting up the contentType
like
$('#upload').ajaxForm({
cache: false,
dataType: 'json',
contentType:"application/json; charset=utf-8",
type: 'POST',
error: function(xhr ,status ,error ) {
alert('error occured. Status:' + status
+ ' --Status Text:' + error
+ ' --Error Result:' + xhr.statusText);
},
timeout: 1000,
data:{ 'path':'path' , 'type':'type' },
complete: function(){
alert('complete');
},
success:function(data){
alert('success');
},
});
精彩评论