douyuai8994 2014-10-06 17:40
浏览 21
已采纳

在模态中显示来自Ajax .post的订阅

I have a modal in index.php which when the button to load it is click I need to display the returned data from an ajax post to a PHP file that returns the subscriptions and if a user is subscribed to one it needs to have a unsubscribe button to the right, if the user is not subscribed it should have a subscribe button.

I cant figure out how to return all the subscriptions and display them in the modal from a ajax post. I know i need to send the data back from the php file in Json format, but I do not know how to get all of the subscriptions and if the user is subscribed all in json format

This is where the Ajax call has to happen

    $(document).on('pagebeforeshow','#subscriptions', function(){
        $.post("getsubs.php",function(data))
    });

To further explain better it should look like this when the modal button is click

Subscription A           ButtonToUnsubscribed(user is already subscribed)
Subscription B           ButtonToUnsubscribed(user is already subscribed)
Subscription C           ButtonToSubscribe(Not subscribed to this one)
  • 写回答

1条回答 默认 最新

  • duanbanzhi4419 2014-10-06 17:55
    关注

    create a php file that queries your database and puts all data in a array and with json_encode() it to a json string and print it out.

    call this php script with ajax and read the json string put it back in an array. and with some if comparing statement creat the buttons needed

    $.ajax({ // ajax call starts
              url: "thephpfile.php",
              data: theData,  ///variable with data to send to php file var1=blabla&var2=blabhsh
              dataType: 'json',
              success: function(data)
              {
                 alert(data); //
              }
          });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题