This is my Django Project structure:
Project
-app_ABC
-json_data
-filter_saved.txt
-site_media
-css
-images
-scripts
-search.js
In My script (search.js) ->I am going to create a script that can write content to file as json format:
function WriteJSONFile(str){
var fh = fopen("json_data/filter_saved.txt", 3);//Open the file for writing
// If the file has been successfully opened
if(fh!=-1) {
fwrite(fh, str); // Write the string to a file
fclose(fh); // Close the file
}
}
$(document).ready(function(){
$("#save_filter").click(function(){
var filter_saved = []
var customer_type_selected = $('#id_customer_type :selected').text();
var list_tag_selected = $("#tag_checked").val();
var filter_name = $("#put_filter_name").val();
filter_saved_JSON = {
"pk":autoincrement,
"customer_type": customer_type_selected,
"tag": list_tag_selected
};
WriteJSONFile(filter_saved_JSON);
});
});
My problems is
var fh = fopen("json_data/filter_saved.txt", 3);//Open the file for writing
Where "filter_saved.txt" Could I put into directory?
I tried to place in many directories in project (I am using ubuntu)
I got an error:
fopen is not defined
[Break on this error] var fh = fopen("json_data/filter_saved.txt", 3);//Open the file for writing\n
Could anyone help me ?
Thanks :)