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)

图片转代码服务由CSDN问答提供 功能建议

我在index.php中有一个模态,当单击加载按钮时我需要显示返回的数据 从ajax帖子到返回订阅的PHP文件,如果用户订阅了一个,则需要在右边有一个取消订阅按钮,如果用户没有订阅,则应该有一个订阅按钮。

我无法弄清楚如何返回所有订阅并在ajax帖子的模态中显示它们。 我知道我需要以json格式从php文件发回数据,但我不知道如何获取所有订阅,如果用户以json格式订阅全部

这是Ajax调用必须发生的地方

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

为了进一步说明,点击模态按钮时它应该是这样的

 订阅A ButtonToUnsubscribed(用户已订阅)
订阅B ButtonToUnsubscribed(用户已订阅)
订阅C ButtonToSubscribe(未订阅此订单)
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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); //
              }
          });
    
    点赞 评论

相关推荐 更多相似问题