PHP End loadmenu.php
$page = $_post ["page"];
$xml = simplexml_load_file (' Menu.xml ');
$root = $xml $page;
$arrJson =array ();
$arrJson ["Key"]= $root->attributes ()->key;//get the name of the menu key
echo Json_encode ($arrJson);
?>
JS End
function Process_menu ()
{
var url = "loadmenu.php";
var params = {' page ': Nowweb};
$.post (url,params,function (data) {menu_back (data);});
}
function Menu_back (response)
{
alert (response);
}
The last message that pops up is: {"key": {"0": "\u8868\u5355\u7ba1\u7406}}
Why not {"key": "Menu Name"}?
Reply to discussion (solution)
function Process_menu ()
{
var url = "loadmenu.php";
var params = {' page ': Nowweb};
$.post (url,params,function (data) {menu_back (data);});
}
$.ajax ({
Type: "POST",
Url:url,
Data:params,
Datatype:jason,
Success:function (response) {
Menu_back (response);
}
});
function Menu_back (response)
{
alert (response);
}
function Process_menu ()
{
var url = "loadmenu.php";
var params = {' page ': Nowweb};
$.ajax ({
Type: "POST",
Url:url,
Data:params,
Datatype:jason,
Success:function (response) {
Menu_back (response);
}
});
function Menu_back (response)
{
alert (response);
}
function Process_menu ()
{
var url = "loadmenu.php";
var params = {' page ': Nowweb};
$.post (url,params,function (data) {menu_back (data);});
}
$.ajax ({
Type: "POST",
Url:url,
Data:params,
Datatype:json,
Success:function (response) {
Menu_back (response);
}
});
function Menu_back (response)
{
alert (response);
}
function Process_menu ()
{
var url = "loadmenu.php";
var params = {' page ': Nowweb};
$.post (url,params,function (data) {menu_back (data);});
}
$.ajax ({
Type: "POST",
Url:url,
Data:param ...
Also no, popup is [object Object]
Datatype:jason,
Datatype:json,
Your response is the string bar. Not a JSON object
Datatype:jason,
Datatype:json,
Your response is the string bar. Not a JSON object
PHP End loadmenu.php
$page = $_post ["page"];
$xml = simplexml_load_file (' Menu.xml ');
$root = $xml $page;
$arrJson =array ();
$arrJson ["Key"]= $root->attributes ()->key;//get the name of the menu key
echo Json_encode ($arrJson);
?>
Is that a problem?
What I'm more curious about is:
1, $root->attributes ()->key no error?
2. The popup message is: {"key": {"0": "\u8868\u5355\u7ba1\u7406}}
Where did this 0 come from?
You better put out a menu.xml, test it.
Reference 5 Floor Ohmygirl's reply: Datatype:jason,
Datatype:json,
Your response is the string bar. Not a JSON object
PHP End loadmenu.php
$page = $_post ["page"];
$xml = simplexml_load_file (' Menu.xml ');
$root ...
Header ("content-type:application/json;charset= .......");
var params = {' page ': Nowweb}; This nowweb is defined, if not, enclosed in quotation marks.
Check if the data returned from PHP is normal.
What I'm more curious about is:
1, $root->attributes ()->key no error?
2. The popup message is: {"key": {"0": "\u8868\u5355\u7ba1\u7406}}
Where did this 0 come from?
You better put out a menu.xml, test it.
Gentlemen, is this question a Chinese garbled problem?
var params = {' page ': Nowweb}; This nowweb is defined, if not, enclosed in quotation marks.
Check if the data returned from PHP is normal.
There's no problem with PHP.
Gentlemen, is this question a Chinese garbled problem?
Not garbled. is just the utf-8 encoding of Chinese in JSON format.
UrlDecode can see the normal output in Chinese. But that is not necessary. Because JS processing JSON is also in accordance with the format of Utf-8
Write like this
$page = $_post ["page"]; $xml = simplexml_load_file (' Menu.xml '); if ($root = $xml, $page) {//The arguments that may be passed are invalid $arrJson = Array (); $arrJson ["key"] = current ($root->attributes ()->key);//Get the name of the menu key Echo json_encode ($arrJson);}
function Process_menu (nowweb) { var url = "loadmenu.php"; var params = {' page ': Nowweb}; $.post (url,params,function (data) { menu_back (data); }, ' json ');} function Menu_back (response) { alert (response.key);} Process_menu (' form '); Test it.
You first direct access to PHP to see if the output is not a problem, if there is a problem, is the PHP side of the problem
function Menu_back (response)
{
Response = eval (' (' +response+ ') ')
alert (response);
}