简体   繁体   English

AJAX,返回php字符串并传递给javascript函数

[英]AJAX, return php string and pass to javascript function

I have a db that stores some email content. 我有一个存储一些电子邮件内容的数据库。 I make an ajax request for the email content, when that's returned I want to pass the content to a function that will display a popup with the email content in there. 我向电子邮件内容提出ajax请求,当返回该电子邮件内容时,我想将内容传递给一个函数,该函数将在其中显示带有电子邮件内容的弹出窗口。 The problem I have is that there are html tags in the email content, which I would like to keep if possible. 我的问题是电子邮件内容中有html标签,如果可能的话,我希望保留这些标签。

I have tried using json_encode and rawurlencode/decodeURIComponent but either the encoded string breaks my below javascript and just displays the email in the page or I get a javascript "Unterminated string literal" error thrown. 我尝试使用json_encode和rawurlencode / decodeURIComponent,但是编码的字符串破坏了我下面的javascript,并仅在页面中显示电子邮件,或者我抛出了javascript“未终止的字符串文字”错误。

var message = "<a href=\"javascript:viewMessage('"+aData[8]+"');\" class=\"glyphicons glyphicons-circle-info\" id=\"comms_msg\"></a>";

Can anyone point me in the right direction? 谁能指出我正确的方向?

If jquery is option, look at this example 如果使用jquery,请看以下示例

 $(function () { var viewMessage=function(msg){ $('#popup').html(msg); // <div id="popup"></div> } $.ajax({ type: 'post', url: "/request/email/content/", // request for email content dataType: "html", success: function (data) { viewMessage(data); } }); }); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM