我正在通过json发送消息,如下所示:
function getMessage() {
$response = [
'message' => sprintf('email sent successfully to %s', '<em>official@mysite.com</em>'),
];
echo json_encode($response);
}
并像这样读取变量:
<span id="mymessage"></span>
$(function() {
$.ajax({
type: 'get',
url: 'getMessage',
dataType: 'json',
success: function(res) {
$('#mymessage').text(res.message);
},
error: function(err) {
console.log(err.responseText);
}
});
});
我希望得到这样的结果:电子邮件已成功发送到 official@mysite.com
但是我却得到如下结果:email sent successfully to <em>official@mysite.com</em>
为什么<em>
标签仍显示为纯字符串,而不是使文本变为斜体?
答案 0 :(得分:1)
请尝试以下更改,首先将字符串直接返回给响应,然后在JS中使用// #include "y.tab.h"
#ifndef AGENT_HEADER_FILE
#define AGENT_HEADER_FILE
typedef enum { typeExpr, typeLit, typeCon, typeAct, typeRule } nodeEnum;
typedef enum { constant, stateVar, varExpr, aritExpr } exprType;
typedef enum { comp, gene, pred, t_f} litType;
/* experssion node */
typedef struct exprNode {
nodeEnum nodeType;
exprType expType; /* type of experssion */
int existSym; /* boolean value whether exists symbol or not */
struct exprNode * left; /* the pointer to left expression */
struct exprNode * right; /* the pointer to right expression */
int iValue; /* value of constant */
char symName; /* name of the variable */
int player; /* me or opponent */
int prop; /* property */
int op; /* operator */
} exprNode;
/* literal node */
typedef struct litNode {
nodeEnum nodeType;
litType literalType; /* type of literal */
int varType;
exprNode * yExpr; /* experission for the row value */
exprNode * mExpr; /* experission for the middle value */
exprNode * xExpr; /* experission for the column value */
int comp_op; /* logical comparison operator */
int true_false;
} litNode;
/* conditions node */
typedef struct conNode {
nodeEnum nodeType;
struct litNode * left; /* the pointer to the current Literal */
struct conNode * right; /* next conditions */
int logop; /* the logical operator */
} conNode;
/* actions node */
typedef struct {
nodeEnum nodeType;
int action; /* type of action */
exprNode * yExpr; /* experission for the row value */
exprNode * xExpr; /* experission for the column value */
} actNode;
typedef struct {
nodeEnum nodeType;
conNode * conditions; /* conditions */
actNode * action; /* action */
} ruleNode;
typedef struct ruleListNode {
ruleNode * curRule;
struct ruleListNode * next;
} ruleListNode;
typedef struct nodeTypeTag {
nodeEnum nodeType;
ruleNode rule;
conNode cond;
actNode act;
exprNode expr;
litNode lit;
} ASTnode;
void playgame(char* name);
#endif
的PHP:
html()
js:
function getMessage() {
$response = [
'message' => 'email sent successfully to '.'<em>official@mysite.com</em>'
];
echo json_encode($response);
exit();
}
如果它可以与$(function() {
$.ajax({
type: 'get',
url: 'getMessage',
dataType: 'json',
success: function(res) {
$('#mymessage').html(res.message);
},
error: function(err) {
console.log(err.responseText);
}
});
});
一起使用,那么您也可以在php中使用.html()