如何包括两个网址在JSON阿贾克斯两个、网址、阿贾克斯、JSON

2023-09-10 20:21:01 作者:蔻丹。

目前,该searchform命中,形式得到提交。然后,它会读取来自指定的URL数据是搜索/ ajax2.php这里返回数据。

所有我要添加是,到包括上述1旁另一个URL,使得两个动作可以同时进行。

现在,在搜索/ ajax2.php它运行一个选择查询。而在这我想包括,这可能是writedb.php它插入从这个贾森考虑到数据库中数据的其他页面。它不必虽然回AJAX页面返回任何东西!

如何实现这一目标?

  $(#searchform)。在(提交,函数(){
        //$(this).find(':submit').attr('disabled','disabled');
        VAR数据= {
            行动:测试
        };

    数据= $(本).serialize()+&放大器; + $ .PARAM(数据);
    $阿贾克斯({
        键入:POST,
        数据类型:JSON,
        网址:搜索/ ajax2.php
        数据:数据,

        成功:功能(数据){

}
});
 
旺哥的欧罗巴杯足球分析 里昂vs阿贾克斯

解决方案

试着增加你的第二个网址sucess功能是这样的:

  $。阿贾克斯({
  键入:POST,
  网址:some_url1,
  数据:一些数据,
  成功:功能(数据){
    $阿贾克斯({
      键入:POST,
      网址:some_url2,
      数据:一些数据,
      成功:功能(数据){}
    });
  }
});
 

Currently, the searchform hit, the form get submitted. Then it will fetch data from specified URL which is search/ajax2.php and return data here.

All I want to add is, to include another URL beside the above mentioned one, so that two actions can be performed at the same time.

Now, in the search/ajax2.php it runs a select query. Whereas in additional page that I want to include, which could be writedb.php it inserts data taken from this jason into database. It doesn't have to return anything back to ajax page though!

How to achieve this?

 $("#searchform").on("submit", function () {
        //$(this).find(':submit').attr('disabled','disabled');
        var data = {
            "action": "test"
        };

    data = $(this).serialize() + "&" + $.param(data);
    $.ajax({
        type: "POST",
        dataType: "json",
        url: "search/ajax2.php",
        data: data,

        success: function (data) {

}
});

解决方案

Try adding your second url in sucess function like this :

$.ajax({ 
  type: 'POST',
  url: 'some_url1',
  data: 'some data', 
  success: function(data){  
    $.ajax ({  
      type: 'POST',
      url: 'some_url2',
      data: 'some data',
      success: function(data){}
    });
  }
});