Click here to Skip to main content
15,173,031 members
Home / Discussions / JavaScript
   

JavaScript

 
QuestionLooking to run a PHP page in the background using pure Javascript Pin
jkirkerx17-Dec-20 14:50
professionaljkirkerx17-Dec-20 14:50 
AnswerRe: Looking to run a PHP page in the background using pure Javascript Pin
DerekT-P17-Dec-20 23:54
professionalDerekT-P17-Dec-20 23:54 
GeneralRe: Looking to run a PHP page in the background using pure Javascript Pin
jkirkerx18-Dec-20 7:10
professionaljkirkerx18-Dec-20 7:10 
GeneralRe: Looking to run a PHP page in the background using pure Javascript Pin
DerekT-P18-Dec-20 8:11
professionalDerekT-P18-Dec-20 8:11 
GeneralRe: Looking to run a PHP page in the background using pure Javascript Pin
jkirkerx18-Dec-20 8:53
professionaljkirkerx18-Dec-20 8:53 
GeneralRe: Looking to run a PHP page in the background using pure Javascript Pin
DerekT-P18-Dec-20 9:26
professionalDerekT-P18-Dec-20 9:26 
GeneralRe: Looking to run a PHP page in the background using pure Javascript Pin
jkirkerx18-Dec-20 9:47
professionaljkirkerx18-Dec-20 9:47 
AnswerRe: Looking to run a PHP page in the background using pure Javascript Pin
jkirkerx18-Dec-20 13:27
professionaljkirkerx18-Dec-20 13: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 14:31
professionaljkirkerx18-Dec-20 14:31 
AnswerGot it Pin
jkirkerx18-Dec-20 14:47
professionaljkirkerx18-Dec-20 14:47 
QuestionFinding the definition of a component from the place of its use Pin
simpledeveloper18-Dec-20 20:43
Membersimpledeveloper18-Dec-20 20:43 
QuestionRe: Finding the definition of a component from the place of its use Pin
Richard MacCutchan18-Dec-20 0:39
mveRichard MacCutchan18-Dec-20 0:39 
AnswerRe: Finding the definition of a component from the place of its use Pin
simpledeveloper18-Dec-20 16:40
Membersimpledeveloper18-Dec-20 16:40 
GeneralRe: Finding the definition of a component from the place of its use Pin
Richard MacCutchan18-Dec-20 23:40
mveRichard MacCutchan18-Dec-20 23:40 
Questiondatepicker on button click not working Pin
Dhyanga17-Dec-20 4:45
MemberDhyanga17-Dec-20 4:45 
QuestionTernary operator Pin
atomattacker-png12-Dec-20 6:06
Memberatomattacker-png12-Dec-20 6:06 
AnswerRe: Ternary operator Pin
Sandeep Mewara12-Dec-20 6:42
mveSandeep Mewara12-Dec-20 6:42 
GeneralRe: Ternary operator Pin
atomattacker-png12-Dec-20 7:01
Memberatomattacker-png12-Dec-20 7:01 
QuestionReference an code behind variable in an external js fn Pin
Member 1492460710-Dec-20 9:42
MemberMember 1492460710-Dec-20 9:42 
AnswerRe: Reference an code behind variable in an external js fn Pin
BabyYoda10-Dec-20 9:58
MemberBabyYoda10-Dec-20 9:58 
GeneralRe: Reference an code behind variable in an external js fn Pin
Member 1492460710-Dec-20 10:45
MemberMember 1492460710-Dec-20 10:45 
AnswerRe: Reference an code behind variable in an external js fn Pin
BabyYoda10-Dec-20 11:06
MemberBabyYoda10-Dec-20 11:06 
GeneralRe: Reference an code behind variable in an external js fn Pin
Member 1492460710-Dec-20 12:27
MemberMember 1492460710-Dec-20 12:27 
QuestionDrawGameScreen funtion not executing Pin
Member 150158428-Dec-20 13:19
MemberMember 150158428-Dec-20 13:19 
SuggestionRe: DrawGameScreen funtion not executing Pin
Richard MacCutchan8-Dec-20 23:24
mveRichard MacCutchan8-Dec-20 23: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.