Rumah >pembangunan bahagian belakang >tutorial php >现在作为一名自学前端开发的学生,对网站的前端与后台数据交互不懂,想学习ajax,很迷茫,不知从何学起?
<code class="language-js"><span class="nx">$</span><span class="p">.</span><span class="nx">ajax</span><span class="p">({</span>
<span class="nx">type</span><span class="o">:</span><span class="s1">'get'</span><span class="p">,</span>
<span class="nx">url</span><span class="o">:</span><span class="s1">'index.php'</span><span class="p">,</span>
<span class="nx">data</span><span class="o">:</span><span class="p">{</span>
<span class="nx">id</span><span class="o">:</span><span class="mi">1</span><span class="p">,</span>
<span class="nx">num</span><span class="o">:</span><span class="mi">2</span>
<span class="p">},</span>
<span class="nx">datatype</span><span class="o">:</span><span class="s1">'json'</span><span class="p">,</span>
<span class="nx">success</span><span class="o">:</span><span class="kd">function</span><span class="p">(</span><span class="nx">data</span><span class="p">){</span> <span class="c1">//这里的data是php返回的数据,参数是data固定不变</span>
<span class="nx">alert</span><span class="p">(</span><span class="nx">data</span><span class="p">);</span>
<span class="c1">//输出php脚本里'echo' 后面的数值,也就是3</span>
<span class="p">}</span>
<span class="p">})</span>
</code>
如果你觉得你需要学习ajax的话,恐怕你更需要学习一样网站大概是怎么运行的。