0

i want to pass other parameters with file to save in database.when i put code to get those variables and save in database it give me alert "SyntaxError: syntax error"... here is my code

$.ajaxFileUpload
    ({
    url:'popup/doc_mydeal.php',
    secureuri:false,
    fileElementId:'deals_documents',
    dataType: 'json',
    data:{rand_key: $('#rand_key').val(), document_name: $('#document_name').val()},
    success: function (data, status)
            {
     if(typeof(data.error) != 'undefined')
                {
                if(data.error != '')
                {
                 alert(data.error);
                 }
             }
            },
            error: function (data, status, e)
            {
                alert(e);
            }
        })

Now on doc_mydeal.php

$tempFile = $_FILES['deals_documents']['tmp_name'];
$targetFile=$path.$_REQUEST['rand_key'].basename($_FILES['deals_documents']['name']);
move_uploaded_file($tempFile,$targetFile);

and here is mysql query to save in database

8
  • Any errors on the PHP side? Commented Mar 6, 2013 at 16:05
  • error in php , js, or somewhere else? Commented Mar 6, 2013 at 16:05
  • 3
    Your dataType is json but you don't return anything. Commented Mar 6, 2013 at 16:06
  • No the same code is working for some time...but some time it give me alert(in javascript) saying "SyntaxError: syntax error" Commented Mar 6, 2013 at 16:07
  • 2
    @Methew Use the json_encode function rather than trying to generate the correct JSON string yourself. Commented Mar 6, 2013 at 16:09

1 Answer 1

2

When you specify a dataType of json in the options for the jQuery AJAX call you're telling the code that the server will be returning valid JSON. Based on this information jQuery will implicitly parse the response text as JSON, passing the resulting object as the argument of the callback function.

In the case that the response text isn't valid JSON the parse will fail and the error callback will be executed instead. As has been pointed out in the comments, what you're returning from your PHP script is invalid JSON.

Sign up to request clarification or add additional context in comments.

2 Comments

but why my data is not saved in mysql table? formating json and returning it is executed later!!
i just want to return filename..what i should do on both sides?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.