Click here to Skip to main content
15,881,898 members
Home / Discussions / JavaScript
   

JavaScript

 
QuestionLooking to run a PHP page in the background using pure Javascript Pin
jkirkerx17-Dec-20 13:50
professionaljkirkerx17-Dec-20 13:50 
AnswerRe: Looking to run a PHP page in the background using pure Javascript Pin
DerekT-P17-Dec-20 22:54
professionalDerekT-P17-Dec-20 22:54 
GeneralRe: Looking to run a PHP page in the background using pure Javascript Pin
jkirkerx18-Dec-20 6:10
professionaljkirkerx18-Dec-20 6:10 
GeneralRe: Looking to run a PHP page in the background using pure Javascript Pin
DerekT-P18-Dec-20 7:11
professionalDerekT-P18-Dec-20 7:11 
GeneralRe: Looking to run a PHP page in the background using pure Javascript Pin
jkirkerx18-Dec-20 7:53
professionaljkirkerx18-Dec-20 7:53 
GeneralRe: Looking to run a PHP page in the background using pure Javascript Pin
DerekT-P18-Dec-20 8:26
professionalDerekT-P18-Dec-20 8:26 
GeneralRe: Looking to run a PHP page in the background using pure Javascript Pin
jkirkerx18-Dec-20 8:47
professionaljkirkerx18-Dec-20 8:47 
AnswerRe: Looking to run a PHP page in the background using pure Javascript Pin
jkirkerx18-Dec-20 12:27
professionaljkirkerx18-Dec-20 12:27 
Well this works, the page takes about 10 secs to run and the spinner turns off. I'm trying to return some JSON back from the PHP page, as an option in case I need to use the option. I should probably post this in the other forum. Anyways, this is my JavaScript.

.then(function(data) is undefined, scratching my head on this. Maybe it's another keyword.

This is what I get back from .then(status = {, which actually looks good. The status below returns when the PHP page is done running. When I think about it, this must be the response header sent when done. So my JSON output should be in this payload within the body I think.

HTTP Status:<br /><br />
Response​<br />
body: ReadableStream { locked: false }​<br />
bodyUsed: false​<br />
headers: Headers {  }​<br />
ok: true​<br />
redirected: false​<br />
status: 200​<br />
statusText: "OK"​<br />
type: "basic"​<br />
url: "<a href="http://0.0.0.0/app/msrpControllerAsync.phtml?save=1&cachebuster=1608332582325">http://0.0.0.0/app/msrpControllerAsync.phtml?save=1&cachebuster=1608332582325</a>"​<br />
<prototype>: ResponsePrototype { clone: clone(), arrayBuffer: arrayBuffer(), blob: blob(), … }<br />
msrpAsync.js:42:25


My JavaScript
C#
spinner.classList.remove('hide');        
spinner.classList.add('show');

const saveUrl = 'msrpControllerTest.phtml?save=1&cachebuster=' + (new Date()).valueOf();

fetch(saveUrl, { mode: 'same-origin', headers: { "Content-Type": "application/json; charset=utf-8" }})
.then(status => {
    console.log("HTTP Status: ", status);
})            
.then(function(data) {

    console.log("Request succeeded with JSON response: ", JSON.stringify(data));      

    // Shut down the spinner
    spinner.classList.remove('show');        
    spinner.classList.add('hide');

})
.catch(err => {

    // Shut down the spinner
    spinner.classList.remove('show');        
    spinner.classList.add('hide');

    console.log("Ajax error - ", err);
    alert("An error has occurred, and no error code has been written yet to debug the error")
});

I wrote this as a PHP 4.3 test page. I don't think that json_encode() will work since it's PHP 4.3.
Remember that I haven't worked with PHP 4 since 2003, so it's been 17 years.
PHP
ob_start();

header('Content-Type: application/json');
$jsonResult = "
{ 
    \'status\': \'202\',
    \'message\': \'No Project Number assigned\',
    \'msrp\': {
        \'bookPrice\': 0.00,
        \'finalAdd\': 0.00
    }            
}";
echo $jsonResult;

ob_end_flush();
If it ain't broke don't fix it
Discover my world at jkirkerx.com

AnswerRe: Looking to run a PHP page in the background using pure Javascript Pin
jkirkerx18-Dec-20 13:31
professionaljkirkerx18-Dec-20 13:31 
AnswerGot it Pin
jkirkerx18-Dec-20 13:47
professionaljkirkerx18-Dec-20 13:47 
QuestionFinding the definition of a component from the place of its use Pin
simpledeveloper18-Dec-20 19:43
simpledeveloper18-Dec-20 19:43 
QuestionRe: Finding the definition of a component from the place of its use Pin
Richard MacCutchan17-Dec-20 23:39
mveRichard MacCutchan17-Dec-20 23:39 
AnswerRe: Finding the definition of a component from the place of its use Pin
simpledeveloper18-Dec-20 15:40
simpledeveloper18-Dec-20 15:40 
GeneralRe: Finding the definition of a component from the place of its use Pin
Richard MacCutchan18-Dec-20 22:40
mveRichard MacCutchan18-Dec-20 22:40 
Questiondatepicker on button click not working Pin
Dhyanga17-Dec-20 3:45
Dhyanga17-Dec-20 3:45 
QuestionTernary operator Pin
atomattacker-png12-Dec-20 5:06
atomattacker-png12-Dec-20 5:06 
AnswerRe: Ternary operator Pin
Sandeep Mewara12-Dec-20 5:42
mveSandeep Mewara12-Dec-20 5:42 
GeneralRe: Ternary operator Pin
atomattacker-png12-Dec-20 6:01
atomattacker-png12-Dec-20 6:01 
QuestionReference an code behind variable in an external js fn Pin
Member 1492460710-Dec-20 8:42
Member 1492460710-Dec-20 8:42 
AnswerRe: Reference an code behind variable in an external js fn Pin
BabyYoda10-Dec-20 8:58
BabyYoda10-Dec-20 8:58 
GeneralRe: Reference an code behind variable in an external js fn Pin
Member 1492460710-Dec-20 9:45
Member 1492460710-Dec-20 9:45 
AnswerRe: Reference an code behind variable in an external js fn Pin
BabyYoda10-Dec-20 10:06
BabyYoda10-Dec-20 10:06 
GeneralRe: Reference an code behind variable in an external js fn Pin
Member 1492460710-Dec-20 11:27
Member 1492460710-Dec-20 11:27 
QuestionDrawGameScreen funtion not executing Pin
Member 150158428-Dec-20 12:19
Member 150158428-Dec-20 12:19 
SuggestionRe: DrawGameScreen funtion not executing Pin
Richard MacCutchan8-Dec-20 22:24
mveRichard MacCutchan8-Dec-20 22:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.