问题
I have a really strange problem with an ajax post. I have many POST-requests in my application and they usually work. On serverside I allow cross-origin requests, like its shown in the Web.config of my C# ASMX webservice:
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET, PUT, POST, DELETE, HEAD, OPTIONS" />
<add name="Access-Control-Allow-Credentials" value="true" />
<add name="Access-Control-Allow-Headers" value="X-Requested-With, origin, content-type, accept" />
</customHeaders>
My application is something like a shop, where you can put items in the cart. the post request (which writes the order in the database) works well when there are less then 5 items in the cart. The request fails when there are 5 or more items in the cart and the following error appears:
> jquery-3.1.1.min.js:4 POST https://url/SP_WRITE_Sperrmuellanmeldung 403 (Forbidden)
send @ jquery-3.1.1.min.js:4
ajax @ jquery-3.1.1.min.js:4
SPWriteSperrmuellanmeldung @ index.js:3470
(anonymous) @ index.js:3380
dispatch @ jquery-3.1.1.min.js:3
q.handle @ jquery-3.1.1.min.js:3
>
>
> /#zsfg_sp_anmelden:1 Failed to load
> https://url/SP_WRITE_Sperrmuellanmeldung:
> No 'Access-Control-Allow-Origin' header is present on the requested
> resource. Origin 'https://sperrmuellportal.ks-weimar.de' is therefore
> not allowed access. The response had HTTP status code 403.
>
and this warning:
> jquery-3.1.1.min.js:4 Cross-Origin Read Blocking (CORB) blocked
> cross-origin response
> https://url/SP_WRITE_Sperrmuellanmeldung
> with MIME type text/html. See
> https://www.chromestatus.com/feature/5629709824032768 for more
> details.
(url
is just a placeholder to the real domain)
It seems that suddenly the headers are missing like you can see in the following screenshot:
The same request with less than 5 items has all the necessary headers:
I realized the request method is always OPTIONS.
I use xml as exchange format. The request itself looks like this:
$.ajax({
type: "POST",
url: UrlToWebservice + "SP_WRITE_Sperrmuellanmeldung",
dataType: 'xml',
data: {
argef: argef.join(";"),
gef_menge: gef_menge.join(";"),
vornameStr: vornameStr,
nachnameStr: nachnameStr,
strasseStr: strasseStr,
hausnrStr: hausnrStr,
hnrzusatzStr: hnrzusatzStr,
dateStr: dateStr,
plzStr: plzStr,
ortStr: ortStr,
telStr: telStr,
mailStr: mailStr,
bemerkungStr: bemerkungStr,
arplz: arplz,
arstrasse: arstrasse,
annahme_art: annahme_art,
benachrichtigung: benachrichtigung,
arnutzererstellt: arnutzererstellt,
arems_typ: sp_arems_typ,
arnutzerweiterg: arnutzerweiterg,
arfraktion: localStorage.getItem("arfraktion")
},
//something more
This is so strange. Does anybody know how to fix it? It drives me crazy. I tried the same request directly on the backend without error, so the backend is able to solve requests like that.
来源:https://stackoverflow.com/questions/51825920/ajax-post-the-response-had-http-status-code-403-headers-are-missing-always-o