json_encode not working with a html string as value

前端 未结 8 1698
太阳男子
太阳男子 2020-12-03 10:02

I am debugging this ajax for quite a time now. I have this on my jQUery file:

$(\"#typeForm\").ajaxForm({
    success : function(html){
        alert(html);
         


        
8条回答
  •  忘掉有多难
    2020-12-03 10:21

    Some stuff to try:

    ajaxForm supports dataType argument, if you expect a JSON coming from the server, use dataType: json like so

    $("#typeForm").ajaxForm({
        success : function(html){
           // html here is already automatically a json object
           alert(html.prompt);
        },
        dataType: 'json'
    }).submit();
    

    Could you post the full service.php? OR try the following:

    exit(json_encode(array('file_name' => $data['upload_data']['file_name'], 'prompt' => $str)));

    -- EDIT --

    Not sure why json_encode returns such weird string :s, is the json_encode a standard php library or an external library? I'm asking this because some servers don't have json_encode in their php installation... I tested on my local and using php internal json_encode and it works fine:

    Nachricht empfangen!
    "; echo json_encode(array('prompt' => $str)); // output //{"prompt":"
    Nachricht empfangen!<\/span><\/div>"}

提交回复
热议问题