douzhi8488 2013-09-30 16:58
浏览 57

mailchimp需要更多API示例 - 发送数据然后重定向

I'm relatively new to mailchimp and have been using this post to implement a very simple email capture form that will redirect to a new landing page on submit. I have been using this post: using an existing form to send data to mailchimp, then redirect

I understand everything in the post except I need an example for this statement:

"However, if you want to redirect, you'd simply alter your jQuery ajax function to do so."

Can someone provide an example of how to alter the jQuery ajax function? Also I don't need it to return a success or failure message, I just need it to capture the name / email and then immediately redirect to the next page.

Thanks

  • 写回答

1条回答 默认 最新

  • dongmei2351 2013-09-30 19:05
    关注

    Sparky is saying that you can modify the success function of the AJAX that is part of the submit function tied to form $('#signup').

    i.e., Currently the success function is:

    ...
    success: function(msg) {
            $('#message').html(msg);
        }
    ...
    

    And you could just update to redirect doing something like:

    ...
    success: function(msg) {
            document.location = '/target/path/file.html';
        }
    ...
    

    EDIT - Doing the above will redirect the browser - so long as the AJAX call is successful (not necessarily that the API call was successful.) So even if the PHP is returning an error in the message - the success function is called because it is referring to the success of the AJAX call itself.

    If you want to redirect only on a successful message returned by the PHP file then you'll have to check the incoming msg and handle accordingly.

    ...
    success: function(msg) {
      if (msg.indexOf('Success') != -1) {
       document.location = '/target/path/file.html';
      } else {
       $('#message').html(msg);
      }
    }
    ...
    

    This will redirect the browser on a successful message return from the PHP file, otherwise it will display the message in $('#message') .

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?