I’m working on a project that uses SharePoint 2010. I need to write a POST variable to a file using an ajax call.
If I were using PHP I would use the fwrite() function to write the POST to a file.
Here is how I envision my solution working. When you go to notarealwebsite.com and submit the form, I envision using an ajax call to write the file. The ajax on the index.php would look like:
$.ajax({
type: 'POST',
url: 'save-text.php',
data: {json: JSON.stringify(strJson)}
});
In PHP I would pass the POST variable into the save-text.php file and its code would look like this:
<? php
$file = fopen("file.txt","w");
fwrite($file, $_POST['json']);
fclose($file);
?>
Does SharePoint have an equivalent function I can use to save the POST to a file?
You don't give us too much here...
You can develop something in JavaScript using a third library like SharepointPlus with the createFile function
You'll do:
$SP().createFile({
content: JSON.stringify(strJson),
destination: "http://mysite/Shared Documents/file.txt",
url:"http://mysite/",
after:function() {
alert("File saved");
}
});
The createFile
of SharepointPlus uses the CopyIntoItems web service of Sharepoint.