douxi3404 2013-11-13 11:05
浏览 37

使用jquery ajax从php函数更新数据

i have two division in my file say form.php....

Division A

All data from table abc (here i am getting data from db)


Division B

Some fields

Add Data (Button) will store data in table abc through ajax using following code (It's storing data)


Now my problem is when i add data in Division B i want to update Division A with newly added data through ajax...

for that i am trying this code but i am getting console error say Uncaught SyntaxError: Unexpected identifier

  $("#addField").click(function(){ 
        label=$("#ilabel").val();
        name=$("#iname").val();
        type=$("#itype").val();
        $.ajax({
            url : 'ajax.php', // this is adding **division B** data in database
            data : {reqtype:'insert',label:label,name:name,type:type},
            type: 'POST',
            success : function(data){ 
                $("#showform").html('<?php echo $d->fetchform() ?>'); // here i am trying to update Division A on success but getting error
            }
        })
    })

$d->fetchform() is giving all the formatted data from the table abc...

i don't know how to deal with this problem.. can you please suggest me how can i do it... (i want to do it through ajax only)

Thanks in advance..

  • 写回答

1条回答 默认 最新

  • dongzun9958 2013-11-13 11:16
    关注

    You are trying to output server-side code (i.e. the PHP echo code) via client-side. This will never work (you'll just end up outputting the whole string inside the html() call as-is, without getting it parsed).

    You should try putting the php fetchForm() call in a web service, or another file on your server, and get the contents of that via AJAX again.

    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line