R
R
rinaz222018-08-27 18:28:22
AJAX
rinaz22, 2018-08-27 18:28:22

AJAX send empty POST?

Hello! There is an AJAX code that sends post data to a php file. Put var_dump($_POST) in php file but it shows empty arrays i.e. the array is empty. This means AJAX is sending empty data. What is the problem?
Here is the AJAX code:

function(e){try{var i,a,d,h,y,b;return e.preventDefault(),$.now()-l<s?void r(t.error,t.interval):(d=[],f.each(function(e){try{var n;if("checkbox-input"===g.fields[e].type?g.fields[e].value=$(this).find("input").prop("checked")?c:u:"radio-list"===g.fields[e].type?g.fields[e].value=$(this).find("[type=radio]:checked").val()||"":"select-menu"===g.fields[e].type?g.fields[e].value=$(this).find("select").val():"hidden"===g.fields[e].type?(g.fields[e].name=g.fields[e].id,g.fields[e].value=$(this).find("input").val()):"file"===g.fields[e].type?g.fields[e].value=$(this).data("result")||"":(n=$(this).find(".form-control").data("placeholder"),g.fields[e].value=n?"":$(this).find(".form-control").val()),g.fields[e].required&&""===g.fields[e].value&&d.push(t.required.replace("%field%",g.fields[e].name)),""===g.fields[e].value)return;if("email"!==g.fields[e].type||/[email protected]+\..+/.test(g.fields[e].value)||d.push(t.email.replace("%field%",g.fields[e].name)),"phone"===g.fields[e].type&&!/.*\d.*\d.*\d.*\d.*/.test(g.fields[e].value))return d.push(t.phone.replace("%field%",g.fields[e].name))}catch(r){error_handler(r,"red libs 21",arguments.callee)}}),"checkbox"===m.privacy&&(i=p.closest(".body").find(".agreement-checkbox input").prop("checked"),h=m.privacy_checkbox.replace(/[<>]/g,""),i===!1&&d.push(t.required.replace("%field%",h))),d.length>0?(p.trigger("error"),void r(t.validate,d.join("\n"))):(b={name:"",phone:"",email:"",count:"",fields:{},item:{},send:g,items:[]},_.each(g.fields,function(e){try{var t;if(""===b[e.type]&&(b[t=e.type]||(b[t]=e.value)),!b.fields[e.name])return b.fields[e.name]=e.value}catch(n){error_handler(n,"red libs 22",arguments.callee)}}),_.each(g.item,function(e){try{var t,n;return(t=b.item)[n=e.type]||(t[n]=_.escape(e.value))}catch(r){error_handler(r,"red libs 23",arguments.callee)}}),_.each(g.items,function(e,t){try{return b.items[t]={},_.each(e,function(e){try{var n,r,i,o;"amount"===e.type||"photo"===e.type?(n=b.items[t])[i=e.type]||(n[i]=e.value):(r=b.items[t])[o=e.type]||(r[o]=_.escape(e.value))}catch(a){error_handler(a,"red libs 25",arguments.callee)}})}catch(n){error_handler(n,"red libs 24",arguments.callee)}}),m.payPrice&&!b.items.length&&b.items.push({amount:1,price:m.payPrice,title:m.payTitle}),n.prop("disabled",!0),y=function(e,i,a){try{var l,u,c,d;return _.defaults(e,b),console.log("Данные формы",{time:e.time,name:e.name,email:e.email,phone:e.phone,count:e.count,fields:e.fields,item:e.item,items:e.items}),n.prop("disabled",!1),0===e.result?(r(t.error,e.errors),p.trigger("error")):1===e.result?(p.trigger("done"),d=n.data("ym_goal"),window.yaCounter&&yaCounter.reachGoal(d),u=n.data("ga_category"),l=n.data("ga_action"),window.ga&&ga("send","event",u,l),"msg"===m.after?o(_.template(m.msg,e),null):"url"===m.after?location.href=_.template(m.url,e):"addhtml"===m.after?$("body").append(_.template(m.addhtml,e)):"pay"===m.after?e.url?location.href=e.url:e.form&&$(e.form).hide().appendTo("body").submit():"msg+url"===m.after?o(_.template(m.msg,e),null,function(){try{return location.href=_.template(m.url,e)}catch(t){error_handler(t,"red libs 27",arguments.callee)}}):"msg+pay"===m.after?o(_.template(m.msg,e),null,function(){try{if(e.url)return location.href=e.url;if(e.form)return $(e.form).hide().appendTo("body").submit()}catch(t){error_handler(t,"red libs 28",arguments.callee)}}):"msg+addhtml"===m.after?o(_.template(m.msg,e),null,function(){try{return $("body").append(_.template(m.addhtml,e))}catch(t){error_handler(t,"red libs 29",arguments.callee)}}):"js"===m.after&&(c="(function () { var time = <%= time %>; var name = '<%- name %>'; var email = '<%- email %>'; var phone = '<%- phone %>'; var count = '<%- count %>'; var fields = <%= JSON.stringify(fields) %>; var item = <%= JSON.stringify(item) %>; var items = <%= JSON.stringify(items) %>; var send = <%= JSON.stringify(send) %>;"+m.js+"})();",$.globalEval(_.template(c,e)))):(r(t.error,null),p.trigger("error")),p.trigger("reset").find("[data-placeholder]").data("placeholder",!0),v.length&&plp.cart.empty(),plp.modal.closeAll(),s=$.now()}catch(f){error_handler(f,"red libs 26",arguments.callee)}},a=function(e,i,o){try{return p.trigger("error"),n.prop("disabled",!1),r(t.error,400===e.status?e.responseText:null),s=$.now()}catch(a){error_handler(a,"red libs 30",arguments.callee)}},$.ajax("/app/c.php",{type:"POST",data:JSON.stringify(g),dataType:"json",contentType:"application/json",processData:!1,success:y,error:y})))}

Here is the HTML:
<div class="modal-body"><div class="macros-form"><div class="outer"><div class="inner"><div class="vertical none size-default"><div class="body"><div class="cont"></div><form class="form text-top" data-form="{&quot;name&quot;:&quot;Виджет \&quot;Кнопка\&quot;&quot;,&quot;type&quot;:&quot;order&quot;,&quot;privacy&quot;:&quot;none&quot;,&quot;privacy_checkbox&quot;:&quot;Даю согласие на <обработку персональных данных>&quot;,&quot;after&quot;:&quot;msg&quot;,&quot;msg&quot;:&quot;Спасибо!\nВаша заявка отправлена.\nВ ближайшее время мы с Вами свяжемся!&quot;,&quot;url&quot;:&quot;/&quot;,&quot;addhtml&quot;:&quot;&quot;,&quot;js&quot;:&quot;alert(\&quot;Этот код выполняется после успешного отправления заявки.\&quot;);&quot;,&quot;integrations&quot;:[]}" data-fields="[{&quot;name&quot;:&quot;Имя&quot;,&quot;type&quot;:&quot;name&quot;,&quot;required&quot;:false,&quot;id&quot;:&quot;&quot;},{&quot;name&quot;:&quot;Телефон&quot;,&quot;type&quot;:&quot;phone&quot;,&quot;required&quot;:true,&quot;id&quot;:&quot;&quot;}]"><div class="fields"><div class="field" data-type="name"><div class="name">Имя</div><div class="input"><input class="form-control text" style="border-radius: 4px;"></div></div><div class="field" data-type="phone"><div class="name">Телефон<span class="required">&nbsp;*</span></div><div class="input"><input class="form-control text" style="border-radius: 4px;"></div></div></div><div class="macros-button"><div class="btn-out full xs-none"><div class="btn-inner"><button class="btn font-text submit" id="uid12" data-ym_goal="" data-ga_category="" data-ga_action=""><span class="text">Отправить заявку!</span><input type="submit"></button></div></div></div></form><div class="cont"></div></div></div></div></div></div></div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pushkarev, 2018-08-27
@AXP-dev

Do you JSON.stringify(g)and gdon't

js code for people
function(e) {
    try {
        var i, a, d, h, y, b;
        return e.preventDefault(), $.now() - l < s ? void r(t.error, t.interval) : (d = [], f.each(function(e) {
            try {
                var n;
                if ("checkbox-input" === g.fields[e].type ? g.fields[e].value = $(this).find("input").prop("checked") ? c : u : "radio-list" === g.fields[e].type ? g.fields[e].value = $(this).find("[type=radio]:checked").val() || "" : "select-menu" === g.fields[e].type ? g.fields[e].value = $(this).find("select").val() : "hidden" === g.fields[e].type ? (g.fields[e].name = g.fields[e].id, g.fields[e].value = $(this).find("input").val()) : "file" === g.fields[e].type ? g.fields[e].value = $(this).data("result") || "" : (n = $(this).find(".form-control").data("placeholder"), g.fields[e].value = n ? "" : $(this).find(".form-control").val()), g.fields[e].required && "" === g.fields[e].value && d.push(t.required.replace("%field%", g.fields[e].name)), "" === g.fields[e].value) return;
                if ("email" !== g.fields[e].type || /[email protected]+\..+/.test(g.fields[e].value) || d.push(t.email.replace("%field%", g.fields[e].name)), "phone" === g.fields[e].type && !/.*\d.*\d.*\d.*\d.*/.test(g.fields[e].value)) return d.push(t.phone.replace("%field%", g.fields[e].name))
            } catch (r) {
                error_handler(r, "red libs 21", arguments.callee)
            }
        }), "checkbox" === m.privacy && (i = p.closest(".body").find(".agreement-checkbox input").prop("checked"), h = m.privacy_checkbox.replace(/[<>]/g, ""), i === !1 && d.push(t.required.replace("%field%", h))), d.length > 0 ? (p.trigger("error"), void r(t.validate, d.join("\n"))) : (b = {
            name: "",
            phone: "",
            email: "",
            count: "",
            fields: {},
            item: {},
            send: g,
            items: []
        }, _.each(g.fields, function(e) {
            try {
                var t;
                if ("" === b[e.type] && (b[t = e.type] || (b[t] = e.value)), !b.fields[e.name]) return b.fields[e.name] = e.value
            } catch (n) {
                error_handler(n, "red libs 22", arguments.callee)
            }
        }), _.each(g.item, function(e) {
            try {
                var t, n;
                return (t = b.item)[n = e.type] || (t[n] = _.escape(e.value))
            } catch (r) {
                error_handler(r, "red libs 23", arguments.callee)
            }
        }), _.each(g.items, function(e, t) {
            try {
                return b.items[t] = {}, _.each(e, function(e) {
                    try {
                        var n, r, i, o;
                        "amount" === e.type || "photo" === e.type ? (n = b.items[t])[i = e.type] || (n[i] = e.value) : (r = b.items[t])[o = e.type] || (r[o] = _.escape(e.value))
                    } catch (a) {
                        error_handler(a, "red libs 25", arguments.callee)
                    }
                })
            } catch (n) {
                error_handler(n, "red libs 24", arguments.callee)
            }
        }), m.payPrice && !b.items.length && b.items.push({
            amount: 1,
            price: m.payPrice,
            title: m.payTitle
        }), n.prop("disabled", !0), y = function(e, i, a) {
            try {
                var l, u, c, d;
                return _.defaults(e, b), console.log("Данные формы", {
                    time: e.time,
                    name: e.name,
                    email: e.email,
                    phone: e.phone,
                    count: e.count,
                    fields: e.fields,
                    item: e.item,
                    items: e.items
                }), n.prop("disabled", !1), 0 === e.result ? (r(t.error, e.errors), p.trigger("error")) : 1 === e.result ? (p.trigger("done"), d = n.data("ym_goal"), window.yaCounter && yaCounter.reachGoal(d), u = n.data("ga_category"), l = n.data("ga_action"), window.ga && ga("send", "event", u, l), "msg" === m.after ? o(_.template(m.msg, e), null) : "url" === m.after ? location.href = _.template(m.url, e) : "addhtml" === m.after ? $("body").append(_.template(m.addhtml, e)) : "pay" === m.after ? e.url ? location.href = e.url : e.form && $(e.form).hide().appendTo("body").submit() : "msg+url" === m.after ? o(_.template(m.msg, e), null, function() {
                    try {
                        return location.href = _.template(m.url, e)
                    } catch (t) {
                        error_handler(t, "red libs 27", arguments.callee)
                    }
                }) : "msg+pay" === m.after ? o(_.template(m.msg, e), null, function() {
                    try {
                        if (e.url) return location.href = e.url;
                        if (e.form) return $(e.form).hide().appendTo("body").submit()
                    } catch (t) {
                        error_handler(t, "red libs 28", arguments.callee)
                    }
                }) : "msg+addhtml" === m.after ? o(_.template(m.msg, e), null, function() {
                    try {
                        return $("body").append(_.template(m.addhtml, e))
                    } catch (t) {
                        error_handler(t, "red libs 29", arguments.callee)
                    }
                }) : "js" === m.after && (c = "(function () { var time = <%= time %>; var name = '<%- name %>'; var email = '<%- email %>'; var phone = '<%- phone %>'; var count = '<%- count %>'; var fields = <%= JSON.stringify(fields) %>; var item = <%= JSON.stringify(item) %>; var items = <%= JSON.stringify(items) %>; var send = <%= JSON.stringify(send) %>;" + m.js + "})();", $.globalEval(_.template(c, e)))) : (r(t.error, null), p.trigger("error")), p.trigger("reset").find("[data-placeholder]").data("placeholder", !0), v.length && plp.cart.empty(), plp.modal.closeAll(), s = $.now()
            } catch (f) {
                error_handler(f, "red libs 26", arguments.callee)
            }
        }, a = function(e, i, o) {
            try {
                return p.trigger("error"), n.prop("disabled", !1), r(t.error, 400 === e.status ? e.responseText : null), s = $.now()
            } catch (a) {
                error_handler(a, "red libs 30", arguments.callee)
            }
        }, $.ajax("/app/c.php", {
            type: "POST",
            data: JSON.stringify(g),
            dataType: "json",
            contentType: "application/json",
            processData: !1,
            success: y,
            error: y
        })))
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question