How to Use AjaxCI to enable the friend watching Function

Source: Internet
Author: User
{Code...} above is HTML {code...} above is the jquery code I wrote. The function is implemented. But why can't I see the result only when I manually refresh this page? The following CI controller is written for guidance .. {Code ...}

0) {echo 'message';}?> ">

Above is HTML

$ ('# Follow'). click (function () {if ($ (". follow"). text () = "follow") {var form_data = {pid:
 , Ajax: '1'}; $. ajax ({url :"
 ", Type: 'post', data: form_data, success: function (msg) {folder ('folder follow'folder .html () ;}});} else {var form_data = {pid:
 , Ajax: '1'}; $. ajax ({url :"
 ", Type: 'post', data: form_data, success: function (msg) {folder ('folder follow'folder .html (msg) ;}});} return false ;})

The above is the jquery code I wrote. The function is implemented,But why can we see the results only when we manually refresh this page?
The following CI controller is written for guidance ..

function addfollow(){    $pid = $this->input->post('pid');    if($this->input->post('ajax')){    }}

Reply content:

0) {echo 'message';}?> ">

Above is HTML

$ ('# Follow'). click (function () {if ($ (". follow"). text () = "follow") {var form_data = {pid:
 , Ajax: '1'}; $. ajax ({url :"
 ", Type: 'post', data: form_data, success: function (msg) {folder ('folder follow'folder .html () ;}});} else {var form_data = {pid:
 , Ajax: '1'}; $. ajax ({url :"
 ", Type: 'post', data: form_data, success: function (msg) {folder ('folder follow'folder .html (msg) ;}});} return false ;})

The above is the jquery code I wrote. The function is implemented,But why can we see the results only when we manually refresh this page?
The following CI controller is written for guidance ..

function addfollow(){    $pid = $this->input->post('pid');    if($this->input->post('ajax')){    }}

Okay, I solved the problem myself. Thanks for the prompt @ joyqi.
It is mainly because no return value is returned when data is operated, and $ ajax must be written in this way.

success:function(msg){  $('#follow').html(msg);}

# Follow returned must be a separate file

Write the CI controller as follows:

function addfollow(){$pid = $this->input->post('pid');if($this->input->post('ajax')){$data['pid'] = $pid;$this->load->view('follow', $data);}}

Your ajax returns the current number of returned results. You can see in your follow js Code.

success:function(msg){             $('#follow').html();        }

Here it should be$('#follow').html(msg);Right

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.