无法将加载了html的php回显数组提取回ajax表单

无法将加载了html的php回显数组提取回ajax表单,php,ajax,Php,Ajax,有谁能帮我解决这个问题吗。我已经研究了好几天了,但我无法将包含html代码的php回声数组格式化为javascript的responseText。 我曾尝试使用json_encode($array)格式化回显数组,但没有成功。 我尝试了responseText.split(“”),然后使用for循环来提取数组中的html代码,但我也不能。 我知道javascript代码正在工作,因为我手动插入了如下html代码: i、 e responseText='这是您的图像' 这很好用,但是当php抛出

有谁能帮我解决这个问题吗。我已经研究了好几天了,但我无法将包含html代码的php回声数组格式化为javascript的responseText。 我曾尝试使用json_encode($array)格式化回显数组,但没有成功。 我尝试了responseText.split(“”),然后使用for循环来提取数组中的html代码,但我也不能。 我知道javascript代码正在工作,因为我手动插入了如下html代码: i、 e

responseText='这是您的图像

'
这很好用,但是当php抛出数组时,我在屏幕上看到的所有代码都是数组字。 我知道我的php代码也在工作,因为我在使用POST方法发送文本之前对其进行了测试

谢谢你的帮助

我的ajax到php


函数ajaxObj(meth,url){
var x=新的XMLHttpRequest();
x、 打开(meth、url、true);
x、 setRequestHeader(“内容类型”、“应用程序/x-www-form-urlencoded”);
返回x;
}
函数ajaxReturn(x){
如果(x.readyState==4&&x.status==200){
返回true;
}
}
函数gotext(){
var mm=document.getElementById(“todotext”).value;
var-isTr=false;
var ajaxfile=ajaxObj(“POST”、“env.php”);
ajaxfile.onreadystatechange=函数(){
if(ajaxReturn(ajaxfile)==true){
document.getElementById(“outputimgs”).innerHTML=ajaxfile.responseText;
}
}
发送(“todotext=“+mm”);
}
$(文档).ready(函数(){
$('form[name=uturn]')。在('submit',函数(e)上{
e、 预防默认值();
gotext();
$('html,body')。设置动画({
scrollTop:$(“#first”).offset().top
}, 1000);
返回false;
});
});

这是html表单



完成!!

结束

这是php中html的动态构造

if(设置($\u POST['todotext'])){
$chunk=$\u POST['todotext'];
$commentArray=explode(“,$chunk);
.
.
.
$commentArray[$i]='


“.$commentArray[$i]”。

”; $together=内爆(“,$commentArray”); 一起回音$;

全部, 我发现了问题所在。正如我所说,网页上唯一出现的是单词数组;该输出来自str_replace,后来被更改为$commentArray[$I]在HTML代码中间回响到ReaveStEXT。我必须把它添加到循环中去修复它。我不知道有什么更好的方法来完成它。其余的HTML被忽略了,为了修复这个问题,我添加了HTMLInTyTyl解码函数。 最后的代码如下所示。 现在一切都很顺利

请参见此处添加的for循环

if(isset($_POST['todotext'])) {

$chunk = $_POST['todotext']; 

$text = explode(" ",$chunk);

$delimiter = array(" ",",",".","'","\"","|","\\","/",";",":","?",">","<","~","_","-","=","+","*","!","@","#","$","%","^","&","(",")");
$replace = str_replace($delimiter, $delimiter[0], $text);

for ($i=0; $i<count($replace); $i++)
{
if ($replace[$i]!==' ')
{
$newreplace .= $replace[$i].' ';
}
}

$newreplace = preg_replace('/\s+/', ' ', $newreplace );


$commentArray= explode($delimiter[0], $newreplace);
if(设置($\u POST['todotext'])){
$chunk=$\u POST['todotext'];
$text=分解(“,$chunk);
$delimiter=数组(“,”,“,”,“,”,“\”,“\”,“\ \”,“/”,“;”,“:”,“?”,“>”,”
<script>
    function ajaxObj( meth, url ) {

    var x = new XMLHttpRequest();

    x.open( meth, url, true );

    x.setRequestHeader("Content-type", "application/x-www-form-    urlencoded");

        return x;

    }

function ajaxReturn(x){

    if(x.readyState == 4 && x.status == 200){

    return true;

    }

}



</script>

<script>

function gotext(){

      var mm = document.getElementById("todotext").value;

      var isTr=false;

      var ajaxfile = ajaxObj("POST", "env.php");

      ajaxfile.onreadystatechange = function() {


         if(ajaxReturn(ajaxfile) == true) {


               document.getElementById("outputimgs").innerHTML = ajaxfile.responseText;


                 }

           }



    ajaxfile.send("todotext="+mm);
}



$(document).ready(function(){
$('form[name=uturn]').on('submit', function(e) {
     e.preventDefault();
     gotext();
    $('html, body').animate({
         scrollTop: $("#first").offset().top
    }, 1000);
    return false;
    });
});
</script>
<form name="uturn" action="process.php" method="post">

<textarea id="todotext" name="text" placeholder="type or paste words here"></textarea><br/>


<input type="submit" id="arefbut" class="button scrolly" value="Convert"/>

</form>



        <!-- First -->


            <section id="first" class="main">


<div class="container">
                        <h2>Done !!</h2>
                <p id="outputimgs">end</p>
</div>
if(isset($_POST['todotext'])) {

$chunk = $_POST['todotext']; 

$commentArray = explode(" ",$chunk);


.
.
.

$commentArray[$i]='<p class="pos"><img src="imgs/blank.png" width="40" height="40"><br>
                                           '.$commentArray[$i].'</p>';


$together = implode(" ",$commentArray);    

echo $together;
if(isset($_POST['todotext'])) {

$chunk = $_POST['todotext']; 

$text = explode(" ",$chunk);

$delimiter = array(" ",",",".","'","\"","|","\\","/",";",":","?",">","<","~","_","-","=","+","*","!","@","#","$","%","^","&","(",")");
$replace = str_replace($delimiter, $delimiter[0], $text);

for ($i=0; $i<count($replace); $i++)
{
if ($replace[$i]!==' ')
{
$newreplace .= $replace[$i].' ';
}
}

$newreplace = preg_replace('/\s+/', ' ', $newreplace );


$commentArray= explode($delimiter[0], $newreplace);
for ( $i=0; $i<$counter;$i++)
{


    $commentArray[$i]= html_entity_decode('<p class="pos"><img src="imgs/black.png" width="40" height="40"><br>'.$commentArray[$i].'</p>');

    }

    $together = implode(" ",$commentArray);

    echo $together;
}