skip to Main Content

I have ajax request function

 function Reject(id, scomment)
  {
      jQuery.ajax({
       type: "POST",
       url: "reject.php",
       data: {id: id, Scomment: scomment},
       cache: false,
       success: function(response)
       {
        location.reload();
       }
     });
 }

There is html from my php loop

<div class="modal-footer">
<textarea id="Scomment" name="Scomment" cols="40" rows="5" class="form-control"></textarea>
<button type="button" class="btn btn-danger" data-dismiss="modal" onClick="Reject('.$row['id'].', "sample text");">Reject</button>
<button type="button" class="btn btn-info" data-dismiss="modal">Close</button>
</div>

So..

If i will use string.

onClick="Reject('.$row['id'].', "sample text");"

console returns Uncaught SyntaxError: Unexpected end of input

But..
If i will use any number instead of "sample text"

onClick="Reject('.$row['id'].', 262434);"

It works.

I am newbie and kindly please support me guys.

2

Answers


  1. You just have to escape your double quotation, this error happens because the starting and ending quote will not match with the current implementation.

    Like this:

    onClick="Reject('.$row['id'].', "sample text");"
    

    Or use single quote instead.

    onClick="Reject('.$row['id'].', 'sample text');"
    
    Login or Signup to reply.
  2. You are using double quotes in double quotes. This leads to problem.

    You can use single quotes in double quotes and viceversa like this

    onClick="Reject('.$row['id'].', 'sample text');"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search