PHP program is deployed on IIS7, Ajax submitted data, encountered two problems, one is cross-domain, a PHP program will always be executed two times.
The first problem of the solution, is Baidu out, add the following lines of code can be:
Header (' access-control-allow-origin:* ');
Header ("Access-control-allow-headers:x-requested-with,content-type");
Header (' Access-control-allow-methods:options,post,get ');
In fact, you can also directly in the IIS settings, do not add code, directly select the site, and then point to the right of the HTTP response header, in the inside directly with the good, you can.
The second problem, has not been Baidu results, had to FQ with Google, a bit on the see, and then follow the clues to find, finally clear.
As described in the cors. NET cross-domain solution (http://jingyan.baidu.com/article/03b2f78c190ad25ea237ae33.html)
The same request requires two methods of the same request address, one labeled "POST" and the other labeled "Options", and the entity method is the method of marking "post", where "OPTIONS" The method does not need to do any logic and the return value is void (in fact, the options request is the browser's checksum, and when the POST request with the parameter is sent, the browser sends an options request to verify the request The header information is consistent with the response header information before actually initiating the POST request)
Grab bag found, indeed, the browser produced two requests, OPTIONS service/service.php http/1.1 and post/service/service.php http/1.1
In this case, I would like to say, let the request options, directly return void, but when you see the configuration of PHP, you can directly restrict the action. Try it, sure enough, now Ajax cross-domain, PHP program only executes once.
IIS configuration method is as follows: Find the PHP program site, you can also choose Server Settings, point to the right of the handler map, find PHP, click Edit, in the pop-up dialog, point request limit, then select the predicate, one of the following predicates, according to the input get,post, I was before for the sake of convenience, It is the default option (all predicates), so this problem is encountered.
When Ajax cross-domain to the PHP program post data, the PHP program always executes two times the workaround