I am having an issue with ZEND, JQuery, PHP, and Javascript. I am very new to these languages, and I am just trying to work my way around them.
I have had jquery.post work in other cases, but I cannot get it to do a simple call right now.
phtml File (/admin/user.phtml)
function testJquery()
{
var url = "<?php echo $myHome2Url.'/admin/newusercallback/sessionid/'.$_SESSION['mySessionId'].'/lang/'.$_SESSION['language']?>";
console.log(url);
$.post(url,{},
function(data)
{
window.alert("Call successful!");
window.alert(data);
},"json");
}
PHP File: (AdminController.php)
public function newusercallbackAction()
{
echo json_encode("Test");
}
A /admin/newusercallback.phtml file exists.
<?php ?>
When run, the console has the following messages printed to it:
POST https://dev.myurl.ca/admin/newusercallback/sessionid/0c1a5e41-ad0a-470d-9901-305464b48908/lang/ENG
https://dev.myurl.ca/admin/newusercallback/sessionid/0c1a5e41-ad0a-470d-9901-305464b48908/lang/ENG
GET https://dev.myurl.ca/admin/user/sessionid/0c1a5e41-ad0a-470d-9901-305464b48908/lang/ENG/report_id/0/
I have 2 popup boxes appearing, which say Call Successful! and Null
The issue is that the second popup box should say "Test" instead of Null.
If I browse to the URL https://dev.myurl.ca/admin/newusercallback/sessionid/0c1a5e41-ad0a-470d-9901-305464b48908/lang/ENG directly, my browser displays a window with the text
"Test"
(quotation marks inclusive)
My question is, why is the callback data for testJquery Null, when browing directly to the page is displaying the data "Test" correctly? Further to that, how can I fix it!
json_encode("Text");tojson_encode(array("result"=>"Test"));andwindow.alert(data);towindow.alert(data.result);json_decode('"Test"');codepad.org/Slqt2Aaq, works also on node.js