开发者

javascript object to php

i'm trying to send an js object to a php function using jquery.ajax.

This is what i have so far:

js side:

 $.ajax({
   type: "GET",
   dataType: "json",
   url: url,
   data: {persoon : persoon2},
   async: false,
   success: function(){
     alert(data);
   return true;
   }
 });

php side:

$decode = json_decode($_GET["persoon"]);
$verzekering->setVoornaam($decode->persoon_voornaam);

in js开发者_如何学C this works: persoon2.persoon_voornaam but i can't get to the value in php, what am i doing wrong?


few fixes

data: "persoon=persoon2", // check input format
success: function(data) { // missing data argument

EDIT your ajax code is working (check URL or php code)

http://jsfiddle.net/ish1301/KZndE/


Found the problem(s)

  1. I was using this inside Drupal and the Jquery version was still 1.2.6. Upgrading it resolved a lot of the problems
  2. The string i tried to catch with the $_GET["persoon"] was mall formated becaus i just send along a js object. Changing

    data: {persoon : persoon2},

to

data: {persoon:JSON.stringify(persoon2)},

fixed the problem

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜