douyun4524 2016-09-27 21:33
浏览 30
已采纳

jQuery成功不会触发代码200

I have next code in PHP:

    $servername = "***";
    $username = "***";
    $password = "***";
    $dbname = "***";

    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }

    $sql = "select * from `opencartdb`.`oc_design` where name='mydesign '";
    $res=$conn->query($sql);
    $records=$res->fetch_assoc();//success 

    $result2=$records['info'];// already json 
    $conn->close();


    echo ($result2);

And i try to catch it with next JS:

jQuery.ajax({
            dataType: "json",
            url: "ajax.php?type=loadDesign&user_id="+user_id+"&design_id="+key
        }).success(function( data ) {
            alert(0);
            console.log((data));
        }).always(function(){
            alert(1);
        });

In the end i see alerted 1 Debuger shows me next result. Response:

{"vectors":"{"front":{"0":{"type":"text","width":"55px","height":"27px","top":"151px","left":"86px","zIndex":"1","svg":"<svg width=\"54.9375\" height=\"27.09375\" viewBox=\"0 0 54.9375 27.09375\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><g id=\"0.5646970888306251\"><text fill=\"#FF0000\" stroke=\"none\" stroke-width=\"0\" stroke-linecap=\"round\" stroke-linejoin=\"round\" x=\"\" y=\"\" text-anchor=\"start\" font-size=\"24px\" font-family=\"arial\" data-textcurve=\"1\" data-itemzoom=\"1 1\" data-textspacing=\"0\"><textPath xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:href=\"http://138.68.62.219/Design-Apple-T-shirt-PC55#textPath-item-0\"><tspan dy=\"0\">Hello</tspan></textPath></text></g><defs><path id=\"textPath-item-0\" d=\"M 0.125 22.117808976867764 A 3093.9720937064453 3093.9720937064453 0 0 1 54.124314613414626 22.117808976867764\"></path></defs></svg>","rotate":0,"text":"Hello","color":"#FF0000","fontFamily":"arial","align":"center","outlineC":"none","outlineW":0}},"back":{}}","teams":"{}","fonts":"","design_id":"1475007569235335440","image":"uploaded/2016/09/design-1475007569235335440.png","parent_id":"0","product_id":"178","product_options":"000000","title":"","description":""}

This lines is painted in debugge:

<svg width=\"54.9375\...
  • 写回答

1条回答 默认 最新

  • dozabt4329 2016-09-27 21:42
    关注

    Set the response type in php to json. Otherwise jQuery might not accept the response type and won´t fire the success function.

    header('Content-Type: application/json'); 
    echo json_encode($result2);
    

    You should also add a charset to avoid BOM:

    header('Content-type:application/json;charset=utf-8');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求
  • ¥20 antv g6 折线边如何变为钝角
  • ¥30 如何在Matlab或Python中 设置饼图的高度
  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao
  • ¥20 Vite 打包的 Vue3 组件库,图标无法显示
  • ¥15 php 同步电商平台多个店铺增量订单和订单状态