【问题标题】:jquery syntax to call script on the server using ajax使用 ajax 在服务器上调用脚本的 jquery 语法
【发布时间】:2016-05-03 08:30:45
【问题描述】:

我们正在使用 jquery 表单插件 (http://jquery.malsup.com/form/#getting-started) 对服务器进行 jquery ajax 后调用。一旦我们得到回应。

我们需要对其进行解析并在服务器上再进行一次 ajax 调用。请让我知道使用 jquery 调用它的语法。

$('#MyForm').ajaxForm({
  success: function(data) {
    console.log("My form submit successful.The response is >>" + data);
    // Process this response and call another script on  the server.
  }
});

【问题讨论】:

  • 它是正确的。您目前面临的当前问题是什么!
  • data 看起来像什么(JSON、HTML、blob...)?第二个ajax调用需要什么,它的类型是什么(POST,GET)?
  • 数据是一个json,第二个ajax也返回一个json。这是 GET 调用。

标签: jquery html ajax forms


【解决方案1】:

在成功函数中添加另一个 ajax 调用,如下所示:

$('#MyForm').ajaxForm({
  success: function(data) {
    console.log("My form submit successful.The response is >>" + data);
    // Process this response and call another script on  the server.

    $.ajax({
      url: 'http://yourURL',
      data: {
        var: 'val',
        ..
      },
      type: 'POST', //GET
      datatype: 'text', //XML,JSON
      success: function(result) {
        //result data handling
      }
      error: functionn() {
        //error handling
      }
    });
  }
});

【讨论】:

    【解决方案2】:

    从回调函数中发出 ajax 请求如下所示:没什么特别的,没什么不寻常的。

    $('#MyForm').ajaxForm({
      success: function(data) {
        console.log("My form submit successful.The response is >>" + data);
        // Process this response and call another script on  the server.
        $.ajax({
           method: "GET", /*string "GET" or "POST"*/
           data: {}, /* query string or object with properties to pass to the server */
           url: "url.com", /* url of the next script */
           success: function () {/* success callback code */},
        });
      }
    });
    

    【讨论】:

      猜你喜欢
      • 2013-05-07
      • 2012-05-24
      • 1970-01-01
      • 1970-01-01
      • 2018-03-09
      • 1970-01-01
      • 2015-04-27
      • 2014-07-08
      • 1970-01-01
      相关资源
      最近更新 更多