0

I have a php script that responds to a file being uploaded. I want to 'echo' this response but I can't get it to work

As you can see in the script below I used ' response ' because I couldn't think of anything. How does this work?

success:function(response){
    if(response == 6563){
        var uploaddiv = document.getElementById('uploadattachment');
        uploaddiv.innerHTML = '<center><br><br><span style="font-size:18px; color:green;">File has successfully been uploaded.</span><br>You can now click this window away or upload another file</center>';
    } else {
        var uploaddiv = document.getElementById('uploadattachment');
        uploaddiv.innerHTML = '<center><br><br><span style="font-size:18px; color:red;">Oops, something went wrong</span><br>' response '</center>';
    }
1

4 Answers 4

4

You forgot to correctly concatenate the string (missing '+'):

uploaddiv.innerHTML = '<center><br><br><span style="font-size:18px; color:red;">Oops, something went wrong</span><br>'+response+'</center>';
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much! Actually did know it had something to do with plusses but din't know it was that similar to PHP :), thanks mate
1

If you want to inspect the response without adding it to the DOM, use console.log(response); and it will be logged to the developed console of your browser.

Comments

1

May be you mean how to get response code status, code sample:

   success: function(data, textStatus, xhr) {
       console.log(xhr.status);
       alert(xhr.status);
   },

So you can handle the response code and process your data according to the status code.

Comments

1

This is the error: You missed a + after and before the response.

var uploaddiv = document.getElementById('uploadattachment');
uploaddiv.innerHTML = '<center><br><br><span style="font-size:18px; color:red;">Oops, something went wrong</span><br>' + response + '</center>';

Comments

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.