,其形式为CSS id(在本例中为#my-form-ID)的名称,如下所示: 希望解决它。它为我工作。 ; - D I have a form that is called via the fancybox plugin login example.Here is the code I have:Form:<form method="post" action="" id="events_form"> <p class="clearfix"><label for="Name">Name:</label> <input type="text" name="Name" id="Name" /></p> <p class="clearfix"><label for="Company">Company:</label> <input type="text" name="Company" id="Company" /></p> <p class="clearfix"><label for="Email">Email:</label> <input type="text" name="Email" id="Email" /></p> <p class="clearfix"><label for="Tel">Tel:</label> <input type="text" name="Tel" id="Tel"/></p> <p class="clearfix"><input type="submit" value="Submit details" /></p> </form>JavaScript / jQuery:<script type="text/javascript"> $(document).ready(function(){ $("#event_trigger").fancybox({ 'padding' : 0, 'scrolling' : 'no', 'titleShow' : false, }); $("#events_form").bind("submit", function() { $.fancybox.showActivity(); $.ajax({ type : "POST", cache : false, url : "/events/index.php", data : $(this).serializeArray(), success: function(data) { $.fancybox(data); } }); return false; }); });</script>The PHP file returns and empty array. However the Firebug post tab displays the form data.Also, I noticed that if I doprint_r($_SERVER['REQUEST_METHOD'])This returns GET, even though I have specified POST. 解决方案 $(this).serializeArray()with the name of the form CSS id (#my-form-ID, in this example) like this:$("#my-form-ID").serializeArray()Hope that solves it. It worked for me. ;-D 这篇关于无法从jQuery Ajax请求中访问数据,返回空数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-20 05:38
查看更多