My problem is that I can not solve this problem
If I call php script I am an undefined error.
This is the code that I use for testing
function startJsonSession () {$ .ajax ({url: "Jsontest.php? Action = startjson", cache: incorrect, data type: "json", complete: function (data) {user name = data; algorithm; warning (user name);} }); } // phpscript if ($ _GET ['action'] == "startjson") {startJson (); } Function startJson () {Header ('Content Type: Application / Jason'); $ Item = ''; Echo json_encode (array ("user name" = "gt; bob", "item" => array ("item1" = "gt; sandwich", "item2" => gt; adspng) )); }
Thanks, Richard
My question has been edited because:
This function gives Jason data in a different way and hence the solution given below Not the same result in
function startChatSession () {$ items = ''; {$ Empty session ($ _ session ['opencatbox']) {foreach ($ _SESSION ['openChatBoxes'] $ chatbox = & gt; $ zero) {$ item. = Chat box session ($ chatbox);} } If the ($ item! = '') {$ Items = substr ($ item, 0, -1);} header ('content-type: application / jason');? & Gt; {"user name": "& Lt ;? php echo $ _SESSION ['username'] ;;>", "item": [
I have rebuilt your code and understood it Taken The type of object is XMLHttpRequest.
Then it works.
var decodedData = eval ("(" + data.responsetext + ")"); Users Name = decodedata.Username; Warning (username);
is a bit messy but it does the trick: -)
ps If it helps, then I Using firebug in firebug and editing JS Code
below: without having to eval, you can use it and it works:
$. GetJSON ("json.php? Action = startjson", function (data) {username = data.username; warning (user name);});
It has been edited to show what I did with the success function:
$ .ajax ({url: "json.php? Action = startjson ", cache: incorrect, datatype:" Jason ", success: function (data) {user name = data. Alarms; warning (user name);}});
Comments
Post a Comment