1

I'm trying to execute some JS right before my Paypal button is clicked, like this:

$('#paypal-button-container form').submit(function(){
  beforePaypalSubmit();
});

The contents of beforePaypalSubmit() are:

function beforePaypalSubmit()
{
  $.ajax({
    type:     'GET'
  , url:      urls.beforePaypalSubmit
  , data:     {
      id: state.id
    }
  , async:    true
  });
}

This simple ajax call should result in a database row being inserted but it isn't. I get 0 PHP error in the logs. Actually, the url doesn't even gets called (checked in the access log). If I do a simple alert() instead of beforePaypalSubmit(), it gets called. What am I missing?

4

2 回答 2

1

尝试在onclick被点击的元素上放置一个事件并提交表单。其中的代码onclick将在提交之前被触发。

于 2013-10-07T11:00:24.267 回答
0

可能不相关,但如果您希望脚本在调用正常提交操作之前运行,请尝试将 async 更改为 false。

于 2013-10-07T10:42:51.097 回答