Problem with ajax or the host?

0 favourites
  • 5 posts
  • I finally done how to save data locally creating a new file in the user folder using NWjs. After that i send the arrays data using ajax and post it to 000webhost through php file. Php file send the data to txt file. All working. Now im trying to retreive the data from the txt file but didnt get it. Nothing get on ajax complete nothing to on ajax progress and nothing on ajax error. Is something wrong with my host i think. Any ideas?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • If you can make the ajax request to send the data and this works fine, it isn't a communication problem. Have you tried to "skip" the file read part and just send a simple string from the php to construct?

    It could be something with the file (permission for example) but again, as you were able to write into the file... Could you post the php lines you using to read the file?

  • For now i dont use any php file to read the data.

    Only to send i used php

    <?php

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

    $postdata = $_POST['postdata'];

    echo($postdata);

    $file = 'Products_List.txt';

    // Open the file to get existing content

    $current = file_get_contents($file);

    // Append a new person to the file

    $current = $postdata;

    // Write the contents back to the file

    file_put_contents($file, $current);

    ?>

    URL -> "https://monday.000webhostapp.com/Products_list.php?postdata"

    Data -> "postdata=" & URLEncode(Array.AsJSON)

    Method -> "POST"

    the file update with the arrays sets.

    When i try to read the Products_List.txt i use

    AJAX request -> "https://monday.000webhostapp.com/Products_List.txt"

    Nothing happen on complete , on progress or on error.

    Cant AJAX read a txt file direct?

    Note that i use NW.js for export.

  • Yes, ajax can "read" anything.

    Your problem is probably because of the CORS. Your php has the explicit (allow access bla bla bla) header while the txt (ofc) doesn't. You'll need a php to read the file too, with the same header.

    Just echo file_get_contents and you're fine.

  • Thank you Cassianno .

    I make a new php file with the same header to read the txt file and it work.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)