如何包括两个网址在JSON阿贾克斯 [英] How to include two URL in json ajax

查看:111
本文介绍了如何包括两个网址在JSON阿贾克斯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,该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
        数据:数据,

        成功:功能(数据){

}
});
 

解决方案

试着增加你的第二个网址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){}
    });
  }
});

这篇关于如何包括两个网址在JSON阿贾克斯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆