3

This is an update of my code. Now I get the values in my update statement, but I still get a parse error. Maybe It has something to do with var update variabele.

    $("#submit_tosolve").on("click",function(e) 
{
alert("ok");

$.valHooks.textarea = {
  get: function( elem ) {
    return elem.value.replace( /\r?\n/g, "\r\n" );
  }
};

// DATA UITLEZEN UIT TEXTAREA
var message =$("#bugcommentaar").val();  //OK
//var solved_ajax=$('input:radio[status3]:checked').val(); //OK DIT NOG IN DATATYPE STEKEN data:
console.log(message);

var request = $.ajax({
  url: "ajax/facebook_ajax.php",
  type: "POST",
  data: {message : message}, //JSON
  dataType: "json"
});

request.done(function(msg) {
if(msg.status=="success"){


  var update='<div style="display:none;" class="span4">'+
  ' <tr>'+'<td>'+'<TEXTAREA class="bugcommentaar">'
  '<p>'+message+' <span> comment posted </span></p></TEXTAREA></tr></td></div>';

$("#comments tr").prepend(update);
$("#comments tr td").first().slideDown(); //dit gaat werken op elke browser, de eerste eruit halen

  }
});

request.fail(function(jqXHR, textStatus) {
  console.log("request failed" +textStatus);
});

//HOU SUBMI TEGEN
e.preventDefault();


});

here is my ajax code: In this code I wan't to update the var message. But I can't do that because I also need var message2 for my id.

 <?php
    session_start();
    include_once("../classes/Bug.class.php");


        if(isset($_POST['message'])) // komt van app.js
        {
            try
            {
                $Bug = new Bug();
                $Bug->Commentaar=$_POST['message'];
                $Bug->Bug_id=$_SESSION["id2sessioncommentaar"];
                $Bug->UpdateCommentaar();   
                $feedback['text'] = "Your comment has been posted!";
                $feedback['status'] = "success";
            }
            catch(Exception $e)
            {
                $feedback['text'] = $e->getMessage();
                $feedback['status'] = "error";
            }

            header('Content-Type: application/json' );
            echo json_encode($feedback);

        }


?>
1
  • So what is the actual problem? If you add $_POST["messageid2"] to your php it should work Commented May 21, 2013 at 17:15

3 Answers 3

4

hi please look this..

var request = $.ajax({
  url: "ajax/facebook_ajax.php",
  type: "POST",
  data: { message : $("#bugcommentaar").val(),
      messageid2: $("#id2").val() 
    },
  dataType: "json"
});
Sign up to request clarification or add additional context in comments.

2 Comments

I tried it but I get a request failed parse error and then i get in my ajax file: UPDATE bugs SET commentaar= '' where bug_id= {"text":"Your comment has been posted!","status":"success"} So theire are no values past to my ajax file.
I have this as output in my console: UPDATE bugs SET commentaar= 'dqsdqsdqs' where bug_id= 61 {"text":"Your comment has been posted!","status":"success"} But I still get a parse error referring to this: request.fail(function(jqXHR, textStatus) { console.log("request failed" +textStatus); });
2

Try changing the data from an object to a string. It's worked for me in the past.

data: "{'message':" + message + ", 'messageid2':" + messageid2+ "}", //JSON

Edit:

Setting the content type might also he

contentType: 'application/json; charset=utf-8',

1 Comment

Hi: I did everything but nothing works. I put also header('Content-Type: application/json ;charset=utf-8'); in my ajax file but that didn't work. Also I can print a string, it must be two seperated values because I need them form my update query.
0

Easy solution is to convert the object into a string by using the JSON built in function stringify.

data: JSON.stringify({message: msgValue, message2: msg2Value})

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.