Click here to Skip to main content
15,891,567 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.

$xmlString;
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."\"}";
}
fclose($handle);
}



Regards
Nanda Kishore.CH
Posted
Updated 14-Nov-16 23:57pm
Comments
Sergey Alexandrovich Kryukov 2-Mar-15 8:43am    
Makes no sense.
—SA

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: http://abandon.ie/notebook/simple-file-uploads-using-jquery-ajax[^]
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 2-Mar-15 8:43am    
5ed.
—SA
Peter Leow 2-Mar-15 9:06am    
Thank you, Sergey.
define(YOUR_CLIENT_ID,'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
define(YOUR_CLIENT_SECRET,'xxxxxxxxxxxxxxx');
if (isset($_GET['code'])) {
$code = $_GET['code'];
//Set the Auth URL
$url = 'https://accounts.google.com/o/oauth2/token';

//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);
curl_close($ch);
if ($info['http_code'] === 200) {
header('Content-Type: ' . $info['content_type']);
return $output;
} else {
die('An error occured');
}
/** Init the curl */

} else {

$url = "https://accounts.google.com/o/oauth2/auth";

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

);

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

//Redirect the page
header("Location: " . $requestTo);
}
 
Share this answer
 

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