开发者

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 eve开发者_StackOverflown 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 i.e

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.

P.S 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜