Callback function is not executed after jquery Ajax post is submitted successfully (in IE environment)

Source: Internet
Author: User

First look at the Code:

Page Ajax post submission code

$. Post ('goods _ QuickAdd. php? Action = updat', {goods_code: $ ('# goods_code1 '). val (), goods_name: $ ('# goods_name1 '). val (), CAT: $ ('# cat1 '). val (), PID: PID, weight: $ ('# weight '). val (), Rand: math. random ()}, function (data) {If (Data = 1) Alert ('Update failed'); else {$ ('# title _' + PID ). text ($ ('# goods_code1 '). val () + ''+ $ ('# goods_name1 '). val (); $ ('# Cat _' + PID ). text ($ ('# cat1 '). find ("option: Selected "). text () ;}$. fancybox. close ();})

Post submission page background processing code: Mainly database operations, return 0 (successful) or 1 (failed) according to the database operation results)

if($db->query($sql))echo 0;elseecho 1;exit;

The above code runs normally in Firefox, but the front-end page does not change when it is executed in IE6 or IE8. After checking, it is found that the background page is running normally (the database operation has been executed ). That is to say, the callback function in IE is not executed.

I used Ajax for a year or two. Most of them use the get method, which has never happened before. I tried to change it to the get method, and then gave up. This is because we have encountered similar problems in the secondary development of ecshop, and we have not found the real cause.

After multiple debugging, the following code is added to the background page, and the callback function in IE can be executed (PHP ).

header('Content-Type:text/html; charset=utf-8');header('Expires: Thu, 01 Jan 1970 00:00:01 GMT');header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');header('Cache-Control: no-cache, must-revalidate, max-age=0');header('Pragma: no-cache');

It is also possible that only one of the above statements can be used. If you are interested, you can try it.

I hope the above methods will be useful in your actual work!

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.