企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] ## 语法 ``` jQuery.post( url [, data ] [, success(data, textStatus, jqXHR) ] [, dataType ] ) 参数说明: dataType 从服务器返回的预期的数据类型。默认:智能判断(xml, json, script, or html)。 ``` ## 示例 ### 返回json格式 ``` $.post("test.php", { "func": "getNameAndTime" }, function(data){ console.log(data.name); // John console.log(data.time); // 2pm }, "json"); ``` ### 完整示例 <details> <summary>index.html</summary> ``` <!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-latest.js"></script> </head> <body> <form action="/" id="searchForm"> <input type="text" name="name" placeholder="Search..." /> <input type="text" name="passwd" placeholder="Search..." /> <input type="submit" value="Search" /> </form> <script> $("#searchForm").submit(function(event) { event.preventDefault(); /* Send the data using post and put the results in a div */ let data = $(this).serialize(); // name=123&passwd=213 let url = $(this).attr("action"); $.post( url, data, function( data ) { var content = $( data ).find( '#content' ); $( "#result" ).empty().append( content ); } ); }); </script> </body> </html> ``` </details> <br />