开发者

Passing more than 1 form field

开发者 https://www.devze.com 2022-12-25 05:11 出处:网络
I\'m trying to update the LastName field for PersonID.I can pass PersonID, but I don\'t know the syntax for also passing the LastName field.

I'm trying to update the LastName field for PersonID. I can pass PersonID, but I don't know the syntax for also passing the LastName field.

$(开发者_开发知识库'input[name="LastName"]').live('focusout', function() {
    var PersonID = $(this).parents("tr").attr("ID");
    var LastName = $(this).val(); // todo: serialize
    $.ajax({
        url:'Remote/Person.cfc?method=UpdateLastName&returnformat=json'
        ,data:'PersonID='+PersonID
    });
    $(this).parents("td").empty().append(LastName);
});

Q: Is is something like data:{'PersonID='+PersonID,'LastName='+LastName}

Am I missing a squiggly line or a parenthesis or comma or dot or colon or semi-colon or plus sign or question mark or an apostrophe or quote or dollar sign or something?


You're close! Change it just a little, no equals in there and use a colon like this:

data: {'PersonID':PersonID, 'LastName':LastName}

You can also do this if you prefer (not as safe if you get some weird characters though)

data: 'PersonID=' + PersonID + '&LastName=' + LastName


For complicated structures in case you add more then 2 vars:

var obj = new Object;
obj.something1 = 'something';
obj.something2 = Array();
obj.something2[1] = 'foo';
obj.something2[2] = 'bar';

//include json2.js
var objJSON =  JSON.stringify(obj);

$.ajax({
      url: "http://example.com",
      type: "GET",
      data: ({obj: objJSON , method : "UpdateLastName"}),
      contentType: "application/json; charset=utf-8",
      dataType: "html",
      success: function(msg){
         alert("Success: " + msg);
      },
      error: function(msg){
         alert("Error: " + msg);
      }
    });

On cf side just do

<cfset test = deserializeJSON(arguments.obj,true) >
0

精彩评论

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