简体   繁体   中英

How to pick up JSON in PHP from Jeditable Script

I want to create a jeditable text area that posts the values entered in to a database and then returns the new value to the div that replaces the textarea. I found this on Stackoverflow that handles returning the new value to the div.

$(document).ready(function() {

     $('.edit_area').editable(submitEdit, { 
            indicator : "Saving...",
            tooltip   : "Click to edit...",
            type : "textarea",
            submit : "OK",
            cancel : "Cancel",
                        name : "Editable.FieldName",
            id   : "elementid",


});
function submitEdit(value, settings)
{ 
   var edits = new Object();
   var origvalue = this.revert;
   var textbox = this;
   var result = value;
   edits[settings.name] = [value];
   var returned = $.ajax({
           url: "http://jimmymorris.co.uk/xmas/record_xmas_msg.php", 
           type: "POST",
           data : edits,
           dataType : "json",
           complete : function (xhr, textStatus) 
           {
               var response =  $.secureEvalJSON(xhr.responseText);
               if (response.Message != "") 
               {
                   alert(Message);
               } 
           }
           });
   return(result);
 }



 });

My problems is I don't know what my POST vars are called so I can insert in to my db. Does it even return POST var to php or does it send php json and how do I know what that is called?

Please help, Cheers in advance.

What it sends to the server depends on what you supply to the "post" mamber of the $.ajax options paremeter.
If you pass a query string parementer data : "name=foo&surname=bar" The PHP script would recieve it in the $_POST variable and could be accessed by means of $_POST['name'] $_POST['surname']
However if you passed an object to the data parameter it would be changed to a query string ie

data : {name : 'foo', surname : 'bar'},

JQuery.ajax would change it into a query string like the example above then It would be sent to the server, and the PHP script would also access it same as mentioned above.

PS I highly recommend using some type of encoding when sending data to the server, encodeURIComponent(variable) and accordingly decode it in PHP by using urldecode.

You have the id posted which you can retrieve in the PHP page as $_POST['id'] . The text is posted as value which you can retrieve in the PHP page as $_POST['value'] . You can of course change the default names.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM