tags:

views:

48

answers:

1

Hello all,

I am using XAMPP + WINDOWS to develop my prototype.

I have designed a form that uses jQuery Form Plugin to do the form submission.

When the form doesn't include FILE field, the return value looks like:

{"success":false,"msg":"incorrect-captcha-sol"} which is jason string.

However, after I add a FILE into the form, I always get sth like

<head></head><body>{"filesize":181,"success":false,"msg":"incorrect-captcha-sol"}<div firebugversion="1.5.4" style="display: none;" id="_firebugConsole"></div></body>

I need to get the filesize information from the server so that I can apply validation rule on the uploaded file. Now the return results look mess and is there way that I can get the json string instead?

Thank you

    var options = { << client script
    target:        '#output',   // target element(s) to be updated with server response 
    beforeSubmit:  showRequest,  // pre-submit callback 
    success:       showResponse,  // post-submit callback 
    url:           'recaptcha.php'  // override for form's 'action' attribute 
}; 
$('#myform').submit(function() { 
    $(this).ajaxSubmit(options); 
    return false; 
});


    $results['success'] = true; << server script snippet
    $results['msg'] = 'Success, you may proceed!';
    echo json_encode($results);
A: 

Everything is right to be honest. Both results is JSON, but the second one (with using the FILE field) is wrapped in document tags. The way it looks, Firebug is messing with your results. This is because AJAX does not support file uploads. If you need to make uploads via AJAX, you will need to use a script like Uploadify or SWFUpload with jQuery.

Good luck!

BigRossLabs
Hello BigRossLabs,Thank you for your comments. I have some followed questions as follows.I am using jQuery Form Plugin to submit my form. So far, it can upload the file to the server without problems.Is it plausible that I parse the return string. For example,<head></head><body>{"filesize":181,"success":false,"msg":"incorrect-captcha-sol"}<div firebugversion="1.5.4" style="display: none;" id="_firebugConsole"></div></body>I need to extract {"filesize":181,"success":false,"msg":"incorrect-captcha-sol"} and then convert it to JSON.Does this method make sense to you?
q0987
Q2> I need to submit both regular form elements and upload FILE.Is that plausible to use Uploadify to do everything?Thank you
q0987