AJAX PHP Loop After clicking on the status change picture

Source: Internet
Author: User
Ajax PHP JavaScript

foreach ($account as $key = $value)
{
?>


');" >


}
else{
?>
');" >







function Xingxing (id,name) {
$.ajax ({
Type: "POST",
URL: " ",
ProcessData: "false",
Data: "n=" + math.random () + "&fn=" + Escape (ID) + "&starflag=" + Escape (name) + "",
Success:function (msg) {
var msg = $.trim (msg);
Switch (msg) {
Case "200":
Location.replace (LOCATION.HREF);
Case "110"://Re-login
Location.replace (LOCATION.HREF);
Case "120"://Change Password
Location.replace (LOCATION.HREF);
Break
Default
Alert ("failure");
Location.replace (LOCATION.HREF);
Break
}
}
});
}

------------------------------------------------------------------------------
My problem is to call the Ajax after the direct replacement of the image does not need to refresh the page, the prawn help, online, etc.


Reply to discussion (solution)

You are not Location.replace (LOCATION.HREF) in the return event of Ajax; , huh?
This is of course to refresh the page

You are not Location.replace (LOCATION.HREF) in the return event of Ajax; , huh?
This is of course to refresh the page
----------------------------------------------

I can block it, and it will refresh automatically.

Switch whole paragraph Delete

Switch whole paragraph Delete
------------------------
Yes, prawn, please code. Thank you!

This is of course to refresh the page
---------------------------------------
Notice is
in the following code is a loop to display the content, click on a picture is not the ID also passed it, Otherwise the click does not reflect
!--? php
foreach ($account as $key + $value)
{
?>
The status of the!--picture 1 show 2 hidden -->
!--? php if ($value [' starflag '] = = 1) {?-->
'); " >
!--here to replace the picture is the loop ID is also to be passed to JS inside it?-->

!--? php
}
else{
?>
'); " >


!--? php}?-->


!--? php}?-->

You are not Location.replace (LOCATION.HREF) in the return event of Ajax; , huh?
This is of course to refresh the page


function Xingxing (id,name) {
$.ajax ({
Type: "POST",
URL: " ",
ProcessData: "false",
Data: "n=" + math.random () + "&fn=" + Escape (ID) + "&starflag=" + Escape (name) + "",
Success:function (msg) {
var msg = $.trim (msg);
$ ("#img_b"). attr ("src", "images/star01.gif");
}
});
}

-----------------------------------
Do not know how to achieve, moderator Badaoxiangchu

$ ("#img_b"). attr ("src", "/themes/default/images/star01.gif");

What is the IM attribute of your img tag?

$ ("#img_b"). attr ("src", "/themes/default/images/star01.gif");

What is the IM attribute of your img tag?

I don't know, I dropped it.

Replacing the attribute with SRC is generally not a problem

If you don't get the right results,

First check the execution to this sentence is not this sentence before there is a mistake

Replacing the attribute with SRC is generally not a problem

If you don't get the right results,

First check the execution to this sentence is not this sentence before there is a mistake
When updating a piece of data, the one above corresponds to whether the ID is updated

Don't know what you're going to do?
Since jquery is used, it's time to use the traditional jquery notation.
PHP section

"Name="
  
    "id="
  
    "/>" name= "
  
    id="
  
   


JS section
$ (function () {  $ (". IMG"). Click (function () {    $ (this). Children (). Toggle ();    $.post ("
 
   ",      {        n:math.random (),        Fn:escape ($ (this). attr (' id ')),        Starflag:escape ($ (this). attr (' name ')      },      function (msg) {        //other processing you need      }  );});
It's the same with $.ajax.
  • 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.