문제

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) >
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top