<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ jQuery - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ freeCodeCamp 是一个免费学习编程的开发者社区，涵盖 Python、HTML、CSS、React、Vue、BootStrap、JSON 教程等，还有活跃的技术论坛和丰富的社区活动，在你学习编程和找工作时为你提供建议和帮助。 ]]>
        </description>
        <link>https://www.freecodecamp.org/chinese/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ jQuery - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/chinese/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Tue, 02 Jun 2026 16:51:36 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/chinese/news/tag/jquery/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ JQuery Ajax POST 方法 ]]>
                </title>
                <description>
                    <![CDATA[ 发送异步 http POST 请求以从服务器加载数据，其一般形式为： jQuery.post( url [, data ] [, success ] [, dataType ] )  * url：是唯一的必需参数。此字符串包含向其发送请求的地址。如果未指定其他参数，则返回的数据将被忽略。  * data：与请求一起发送到服务器的对象或字符串。  * success：如果请求成功，将执行这个回调函数。它将返回的数据作为参数，它还传递了响应的文本状态。  * dataType：服务器期望的数据类型，默认值为 Intelligent    Guess（xml、json、脚本、文本、html）。如果提供了此参数，则还必须提供 success 回调。 示例 $.post('http://example.com/form.php', {category:'client', type:'premium'}); 从服务器请求 form.php，发送其他数据并忽略返回的结果。 $.post('http://example.com/form.php', {category:'client', t ]]>
                </description>
                <link>https://www.freecodecamp.org/chinese/news/jquery-ajax-post-method/</link>
                <guid isPermaLink="false">603375e3c354c605689ea5cf</guid>
                
                    <category>
                        <![CDATA[ jQuery ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ajax ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp.org ]]>
                </dc:creator>
                <pubDate>Wed, 20 Jan 2021 09:20:00 +0000</pubDate>
                <media:content url="https://chinese.freecodecamp.org/news/content/images/2021/02/photo-1466096115517-bceecbfb6fde.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>发送异步 http POST 请求以从服务器加载数据，其一般形式为：</p><pre><code class="language-javascript">jQuery.post( url [, data ] [, success ] [, dataType ] )</code></pre><ul><li>url：是唯一的必需参数。此字符串包含向其发送请求的地址。如果未指定其他参数，则返回的数据将被忽略。</li><li>data：与请求一起发送到服务器的对象或字符串。</li><li>success：如果请求成功，将执行这个回调函数。它将返回的数据作为参数，它还传递了响应的文本状态。</li><li>dataType：服务器期望的数据类型，默认值为 Intelligent Guess（xml、json、脚本、文本、html）。如果提供了此参数，则还必须提供 success 回调。</li></ul><h4 id="-"><strong><strong><strong>示例</strong></strong></strong></h4><pre><code class="language-javascript">$.post('http://example.com/form.php', {category:'client', type:'premium'});</code></pre><p>从服务器请求 <code>form.php</code>，发送其他数据并忽略返回的结果。</p><pre><code class="language-javascript">$.post('http://example.com/form.php', {category:'client', type:'premium'}, function(response){ 
      alert("success");
      $("#mypar").html(response.amount);
});</code></pre><p>从服务器请求 <code>form.php</code>，发送其他数据并处理返回的响应（json 格式）。该示例可以用以下格式编写：</p><pre><code class="language-javascript">$.post('http://example.com/form.php', {category:'client', type:'premium'}).done(function(response){
      alert("success");
      $("#mypar").html(response.amount);
});</code></pre><p>以下示例使用 Ajax 发布表单并将结果放入 div 中：</p><pre><code class="language-html">&lt;!doctype html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;title&gt;jQuery.post demo&lt;/title&gt;
  &lt;script src="https://code.jquery.com/jquery-1.10.2.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
 
&lt;form action="/" id="searchForm"&gt;
  &lt;input type="text" name="s" placeholder="Search..."&gt;
  &lt;input type="submit" value="Search"&gt;
&lt;/form&gt;
&lt;!-- 搜索结果将在这个 div 中渲染 --&gt;
&lt;div id="result"&gt;&lt;/div&gt;
 
&lt;script&gt;
// 将提交处理程序附加到表单
$( "#searchForm" ).submit(function( event ) {
 
  // 阻止表格正常提交
  event.preventDefault();
 
  // 从页面元素中获取一些值：
  var $form = $( this ),
    term = $form.find( "input[name='s']" ).val(),
    url = $form.attr( "action" );
 
  // 用 post 发送数据
  var posting = $.post( url, { s: term } );
 
  // 将结果放在 div 中
  posting.done(function( data ) {
    var content = $( data ).find( "#content" );
    $( "#result" ).empty().append( content );
  });
});
&lt;/script&gt;
 
&lt;/body&gt;
&lt;/html&gt;</code></pre><p>以下示例使用 GitHub API，通过使用 jQuery.ajax() 获取用户的仓库列表，并将结果放入 div 中：</p><pre><code class="language-html">&lt;!doctype html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;title&gt;jQuery Get demo&lt;/title&gt;
  &lt;script src="https://code.jquery.com/jquery-1.10.2.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
 
&lt;form id="userForm"&gt;
  &lt;input type="text" name="username" placeholder="Enter gitHub User name"&gt;
  &lt;input type="submit" value="Search"&gt;
&lt;/form&gt;
&lt;!-- 搜索结果将在这个 div 中渲染 --&gt;
&lt;div id="result"&gt;&lt;/div&gt;
 
&lt;script&gt;
// 将提交处理程序附加到表单
$( "#userForm" ).submit(function( event ) {
 
  // 阻止表单正常提交
  event.preventDefault();
 
  // 从页面元素中获取一些值：
  var $form = $( this ),
    username = $form.find( "input[name='username']" ).val(),
    url = "https://api.github.com/users/"+username+"/repos";
 
  // 用 post 发送数据
  var posting = $.post( url, { s: term } );
 
  //Ajax 函数，发送 get 请求
  $.ajax({
    type: "GET",
    url: url,
    dataType:"jsonp"
    success: function(response){
        //如果请求成功，则响应数据

        $( "#result" ).empty().append( response );
    }
  });
  
});
&lt;/script&gt;
 
&lt;/body&gt;
&lt;/html&gt;</code></pre><h3 id="jquery-ajax-"><strong><strong><strong>jQuery.ajax()</strong></strong></strong></h3><p><code>$.post( url [, data ] [, success ] [, dataType ] )</code> 是一个简写的 Ajax 函数，等同于：</p><pre><code class="language-javascript">$.ajax({
  type: "POST",
  url: url,
  data: data,
  success: success,
  dataType: dataType
});</code></pre><p><code>$.ajax()</code> 还有更多选项，可点击<a href="http://api.jquery.com/jquery.ajax/" rel="nofollow">这里</a>查看。</p><h4 id="--1"><strong><strong><strong>更多信息</strong></strong>：</strong></h4><p>请在<a href="https://api.jquery.com/jquery.post/" rel="nofollow">官网</a>查看更多信息。</p><p>原文：<a href="https://www.freecodecamp.org/news/jquery-ajax-post-method/">JQuery Ajax POST Method</a></p> ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
