AJAX cannot access an object data value passed from php -
I have a php.php file to get the data, then pass the result back to AJAX, like this: < / P>
& lt ;? Php $ p1 = $ _POST ["p1"]; $ C1 = $ _POST ["C1"]; $ Resultx ['r1'] = "XXX"; $ Resultx ['r2'] = 0; $ Resultx ['r3'] = 100; $ Result area ['R4'] = 1000; Echo json_encode ($ resultx);
And I have in my JS file:
$ Ajax ({url: 'php.php', type: 'post', data: {P1: 5, c1: 100}, cache: false, success: function (result x) {var results = result x; console.log (Mys); var my1 = document.getElementById ('my1' ; My1.textContent = "id:" + result.r1; my2.textContent = "rank:" + Result.r2; my3.textContent = "total players:" + result.r3; my4.textContent = "top credit:" + Result.r4;},});
my1 my2 my3 my4 fields are undefined with all print, however the console shows the value of the log:
{"r1": "XXX" var results = result x; / code> to
var result = JSON.parse (resultx)
An error of the JavaScript console Message print untold syntax error unexpected token
.
Please help!
Comments
Post a Comment