"包括与HTML code&QUOT一个PHP文件;与Ajax响应工作文件、工作、HTML、QUOT

2023-09-10 14:05:08 作者:风吹过老故事

朋友你好我有一个PHP code的一个问题,我需要有一个Ajax响应工作。

Hello friends I have a problem with a php code that I need to work with an AJAX response.

PHP code没有工作,PHP Ajax响应:

php code not work to php ajax response:

if($_GET){
    $data['form']   =       $this   ->  AJAXFORM        ->  GetHTMLAjaxForm();
    $return = json_encode(array('form'=>$data['form']));
    echo $return;
}

GetHTMLAjaxForm()//功能

GetHTMLAjaxForm() //the Function

function GetHTMLAjaxForm(){
    $htmlform       =       include('adduser.php'); 
    return $htmlform;
}

文件adduser.php有enterely HTML code需要被用作Ajax回调的响应,plzz检查,说我有没有当我使用它得到这个错误becouse任何错误:

the file adduser.php have enterely html code that need to be use as a response of ajax callback, plzz check it and say me if i have any mistake becouse when i use it get this error:

Ajax, php respond array data error SyntaxError: JSON.parse: unexpected character at line 4 column 7 

更新 这一工作的一部分,现在已成了下面列出的一个新的问题:

Update with this working part, now lies in a new problem listed below:

Html与阿贾克斯插入()不与其他的.js脚本

推荐答案

终于得到运行这个想法是要仔细GET请求由阿贾克斯

to finally get to run this idea was necessary to double GET request by .ajax

function GetForms(id){
    $.ajax({
        type:   "GET",
        dataType: "json",
        url:        "index.php",
        data:   {idfield:id},
        error: function(xhr,status,error){alert(error);},
        success:    function(data) {
            $("#areatitle").html(data.title);
        }
        });
    $.ajax({
        type:   "GET",
        url:        "index.php",
        data:   {idform:id},
        error: function(xhr,status,error){alert(error);},
        success:    function(response) {
            $("#formarea").html(response);
        }
    });
}

和PHP文件:

if($_GET){
    if(@$_GET['idfield']){
        $return = json_encode(array('title'=>'titulo nuevo'));
        echo $return;
    }
    if(@$_GET['idform']){
        $data   =       $this   ->  AJAXFORM        ->  GetHTMLAjaxForm();
        echo $data;
    }
}

其实我要的是简化的请求到服务器的数量,并利用这种控制是非常重要的。

actually what I want is to simplify the amount of request to the server, and to take control of this would be very important.

如果有人有一个更好的主意favort在这个岗位交流。

if someone has a better idea favort communicate in this post.

这个工作的一部分,现在已成了下面列出的一个新的问题:

Html与阿贾克斯插入()不能与其他的.js脚本工作

Html inserted with .ajax() not work with other .js script