简体   繁体   English

jQuery-如何在ajax发布页面上发送ajax发布

[英]jQuery - How to send ajax post on ajax post page

I need to send ajax post on ajax posted page. 我需要在ajax发布页面上发送ajax发布。

index.php has index.php有

$.ajax({ type: "POST",datatype:"json", url: "/notification.php",      
data: "kime=karaakce&tur=konuyayorum&postid=2020",
success: function(html){
}
});

notification.php has same function but posts to track.php notification.php具有相同的功能,但发布到track.php

$.ajax({ type: "POST",datatype:"json", url: "/track.php",      
data: "kime=karaakce&tur=konuyayorum&postid=2020",
success: function(html){
}
});

However, notification.php doesnt send the ajax post. 但是,notification.php不会发送ajax帖子。 How can I make it run ? 我如何使其运行?

First thing you cannot run the jquery code even if you include it in your notification.php file. 第一件事,即使您将jquery代码包含在notification.php文件中,也无法运行它。 That is because jquery runs only in browser, not at backend. 这是因为jquery仅在浏览器中运行,而不在后端运行。 So unless you "physically" open the notification.php page in browser the jquery won't run. 因此,除非您以物理方式在浏览器中打开notification.php页面,否则jquery将不会运行。

So to address your issue you'll have to chain the success response from one php file to next. 因此,要解决您的问题,您必须将成功响应从一个php文件链接到另一个文件。

eg: Data from index.php ---> notification.php ---> index.php ---> track.php (Although a very crude approach) 例如:来自index.php的数据---> notification.php ---> index.php ---> track.php(尽管这是非常粗略的方法)

Here is the code that can achieve this. 这是可以实现此目的的代码。

index.php file index.php文件

$.ajax({ 
    type: "POST",
    datatype:"json", 
    url: "/notification.php",      
    data: {
            kime=karaakce,
            tur=konuyayorum,
            postid=2020
          }
    success: function(responseData){
           $.ajax({ 
                     type: "POST",
                     datatype:"json", 
                     url: "/track.php",      
                     data: {
                              kime=karaakce,
                              tur=konuyayorum,
                              postid=2020
                     }
                     success: function(html){
                        // This is your final success 
                  }
               });
   }
});

Your notification.php file should return a JSON data which you can use to send it to the next request. 您的notification.php文件应返回一个JSON数据,您可以使用该数据将其发送到下一个请求。 It will come in 'responseData' object. 它将出现在“ responseData”对象中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM