为什么我的 ajax 调用没有生成,因为我包含 ajax 的 js 文件包含在 iframe 中


why my ajax call is not getting generated as my js file which contain ajax is included inside an iframe?

在下面的代码中,url没有被调用实际上ajax不起作用,是否有任何jquery冲突或其他..

var request = $.ajax({
    url: "https://subscribe.php",
    data: params,
    type: 'post',
    dataType: 'json',
    success: function(data) {
        if (!data == '') {
            alert(data);
            if (data.success == 1) {
                alert('Thank you for subscribing.');
                return false;
            } else {
                alert(data.message);
                return false;
            }
        }
    }
});

提前感谢你...

Ajax 是一个异步调用,$.ajax() 不返回任何响应。

请参阅 http://api.jquery.com/jquery.ajax/链接以了解jQuery.ajax()的用法。

您的代码应该是:

$.ajax({
  url: "https://subscribe.php",
  data : params,
  type : 'post',
  dataType: 'application/json',
  success: function(data){ // this is a call back function.
            if (!data == ''){
                alert(data);
                if (data.success == 1){
                    alert('Thank you for subscribing.');
                    // Do your call
                }else{
                    alert(data.message);
                    return false;
                }
            }
        }              
});

您可以在 jQuery.ajax() 中使用许多其他选项。要了解详细用法,请转到上面提到的URL。