-1

I'm trying to fetch data from a website; however, it return a PHP file as text without the result that I look for (the result after enter all required input) after sending out all the information by using 'POST' method to the server

Down here is my code that I used to fetch info:

var form = {
    'cp': poke_cp,
    'p_id': poke_id,
    'hp': poke_hp,
    'dust': poke_dust,
    'up': "1"
};
$.ajax({
    type: 'POST',
    url: "https://pokefind.co/ivcalc.php",
    dataType: "text",
    data: form,
    success: function (data) {
        console.log(data);      
    }
});
Box Box Box Box
  • 5,094
  • 10
  • 49
  • 67
  • Can you post the contents of your PHP file? – Barry Thomas Sep 09 '16 at 18:35
  • 1
    What you're trying to do will never work unless the server owner sets up CORS to your server. This is also known as the [Same-origin policy](https://en.wikipedia.org/wiki/Same-origin_policy) – icecub Sep 09 '16 at 18:35
  • 1
    `it return a php file as text` <-- what does this mean? What response are you seeing? Tbh I don't think this will work either way. – Jonnix Sep 09 '16 at 18:35
  • Possible duplicate of [why are my php files showing as plain text?](http://stackoverflow.com/questions/3555681/why-are-my-php-files-showing-as-plain-text) – Sensei James Sep 09 '16 at 18:54
  • And your question is...? – Mr Anderson Sep 09 '16 at 19:26

1 Answers1

0

As said in comments by @icecub, if the remote server does not allow cross origin requests you will not be able to fetch datas from the website.

The page you are trying to POST seems be the page that handle a form. So you have two problems :

  • CSRF, during the form handle there is a verification to be sure that you come from the form page
  • Cross Origin possibly not allowed.

If the website has a WebService you should use it.

Community
  • 1
  • 1
Anthony
  • 2,014
  • 2
  • 19
  • 29