Click here to Skip to main content
14,733,301 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
Hi Team,

i have PHP code, here i need to convert this code to jquery in my application. If there is know anyone could you share the knowledge.

if (isset($_POST['xmlString'])){
$filename = $_POST['xmlFilename'];
$xmlString = stripslashes($_POST['xmlString']);

$newFile = "_data/".$filename.".edit.xml";

//write new data to the file, along with the old data
$handle = fopen("../".$newFile, "w");
if (fwrite($handle, $xmlString) === false) {
echo "{error:\"Couldn't write to file.\"}";
else {
echo "{filename:\"".$newFile."\"}";

Nanda Kishore.CH
Updated 15-Nov-16 0:57am
Makes no sense.

According to the PHP code, it is writing some uploaded xml content to a file on server. This is the job of a server-side script like PHP. jQuery, on the other hand, cannot do this, jQuery, which is a library of JavaScript, belongs to client-side scripting, which means it only runs on the browser. You may upload a file using jQuery Ajax from the browser and be processed by PHP on the server. See example:[^]
Peter Leow 2-Mar-15 9:06am
Thank you, Sergey.
if (isset($_GET['code'])) {
$code = $_GET['code'];
//Set the Auth URL
$url = '';

//Set the Auth Parameter
$redirectUri='http://' . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"];
$params = array(
"client_id" => YOUR_CLIENT_ID,
"client_secret" => YOUR_CLIENT_SECRET,
"redirect_uri" => $redirectUri,
"grant_type" => "authorization_code",
"code" => $code,

/** Init the curl */
$ch = curl_init();
curl_setopt($ch, constant("CURLOPT_" . 'URL'), $url);
curl_setopt($ch, constant("CURLOPT_" . 'POST'), true);
curl_setopt($ch, constant("CURLOPT_" . 'POSTFIELDS'), $params);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
if ($info['http_code'] === 200) {
header('Content-Type: ' . $info['content_type']);
return $output;
} else {
die('An error occured');
/** Init the curl */

} else {

$url = "";

//Set the Auth Parameter
$params = array(
"response_type" => "code",
"client_id" => YOUR_CLIENT_ID,
"redirect_uri" => 'http://' . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"],
"scope" => "" //I have added scope for webmaster tool


$requestTo = $url . '?' . http_build_query($params);

//Redirect the page
header("Location: " . $requestTo);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900