Glenda
Glenda

Reputation: 79

$.ajax() jquery how to send multiple data values

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);

        }


?>

Upvotes: 3

Views: 16108

Answers (3)

Jay Jara
Jay Jara

Reputation: 99

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})

Upvotes: 0

Smeegs
Smeegs

Reputation: 9224

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',

Upvotes: 2

Javal Patel
Javal Patel

Reputation: 838

hi please look this..

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

Upvotes: 4

Related Questions