简体   繁体   中英

Is it possible for a local html file to fill out and send an external PHP form?

I'm attempting to create an HTML-file that acts as a direct link to a cached site made by proxysite . Is there any way I can send a form containing a URL, without having the user fill in any field?

Sending it via ajax like so:

var params = {
    "d" : "http://www.web.site/"
};

$.ajax({
    url: "https://eu1.proxysite.com/includes/process.php?action=update",
    type: "POST",
    data: params
});

Seems to be purposefully blocked, as it returns this error message:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

EDIT: I realize why the above won't work. Since I don't have access to the previously mentioned website, I am looking for a possible workaround.

The reason you are receiving the "No Access-Control-Allow-Origin" header is because the receiving server needs to provide CORS headers. If you have access to the proxysite you will need to set the following headers to allow your request to go through

 <?php
 header("Access-Control-Allow-Origin: *");

Where the asterisk is the domain you want to allow. If you leave the asterisk in the the server will accept all requests from any local scripts on any domain.

Regarding sending the form without having the user input any fields-- Yes, it's possible to send data without user input. The way you are doing it is the correct way to send data via the jQuery Ajax method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM