开发者

different values for POST value?

开发者 https://www.devze.com 2023-02-20 08:20 出处:网络
I have a contact edit form. The entire form is requested through ajax (loaded into a lightbox). The form is preloaded with the contacts data.

I have a contact edit form.

The entire form is requested through ajax (loaded into a lightbox).

The form is preloaded with the contacts data.

When you click edit jQuery checks for the differences in the form and sends only the changed inputs back.

This works fine except.

on localhost doing echo $_POST['data'] gives [{"name":"firstName","value":"James"}]

doing it on production gives [{\"name\":\"firstName\",\"value\":\"James\"}]

Where are the extra \ coming from.

If it helps

localhost = windows, php 5.3

production = linux php 5.2

let me know if you need any more code

var contact = $(this).attr('rel');
$.facebox(function() {
  $.ajax({
    url: site_url + 'ajax/contact',
    type: 'POST',
    data: {
      id: contact,
      method: 'editForm'
    },
    success: function(data) {
      $.facebox(data);
      $('#editForm').submit(function() {
        var data = [];
        var finalForm = $(this).serializeArray();
        var differences = 0;
        for (var i in initialForm) {
          if (!objectsAreSame(initialForm[i], finalForm[i])) {
            data[differences] = finalForm[i];
            differences++;
          }
        }
        if (differences > 0) {
          $.ajax({
            url: site_url + 'ajax/contact',
            type: 'POST',
            data: {
              id: finalForm[0].value,
              method: 'editContact',
              data: JSON.stringify(data)
            },
            success: function(data) {
              $('#contact' + finalForm[0].value).hide("drop", {direction: 'up'}, 500, 
              function() {
           开发者_JAVA技巧     $('#contact' + finalForm[0].value).replaceWith(data);
                $('#contact' + finalForm[0].value).show("drop", {direction: 'up'}, 500, function() {
                  $(document).trigger('close.facebox');
                });
              });
              return false;
            }
          });
        }
        $(document).trigger('close.facebox');
        return false;
      });
      $('#accordion').accordion();
      initialForm = $('#editForm').serializeArray();
    }
  });
});


Have a look at http://php.net/manual/en/security.magicquotes.php . On you development machine, since you are running 5.3.0 they are deprecated. On your production machine they are enabled. Check on how to disable them but be sure to double-check your code.


These are only the escape characters for your double quotes. Its probably only the interpreter displaying it differently for you and shouldn't have any bearings on the actual behavior of the POSTed variables.


echo stripslashes($_POST['data']);

http://www.tizag.com/phpT/php-magic-quotes.php

0

精彩评论

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