$ .ajax()jquery如何发送多个数据值

时间:2022-05-19 22:10:17

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.

这是我的代码的更新。现在我在更新语句中获取值,但仍然出现解析错误。也许它与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.

这是我的ajax代码:在这段代码中我不想更新var消息。但是我不能这样做,因为我的id也需要var message2。

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

        }


?>

2 个解决方案

#1


4  

hi please look this..

嗨,请看这个..

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

#2


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


4  

hi please look this..

嗨,请看这个..

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

#2


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