Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery AJAX Call to PHP Script with String Return
    primarykey
    data
    text
    <p>My aim here is to replicate the Hot Towel SPA framework from ASP.NET in PHP.</p> <p>I have two files in my project: show.js and displaystring.php. What I basically want to do is return whatever is present in the displayString() function. But due to a series of unsuccessful attempts, I inserted the debugger statement in the shows.js file (as marked in the source code below) to find out what's wrong. When I run the project in Google Chrome and open the developer tools (Ctrl + Shift + i), I see that the program flow stops at the debugger statement (as expected) and when I hover my mouse over the data variable in the success property, I see that the displaystring.php file returns me the entire html source code instead of just returning the ".$_POST('string'); statement.</p> <p>I have gone through many solutions on the internet but to no avail. Can anyone please tell me where exactly am I going wrong? Thank you.</p> <p>show.js</p> <pre><code>define(function (require) { var val = ""; //var moviesRepository = require("repositories/moviesRepository"); $.ajax({ url: "controllers/displaystring.php", type: "post", data: {input:"show"}, datatype: 'json', success: function(data){ val = data; debugger; // Debugger inserted here. }}); return { result: ko.observable(), activate: function() { this.result(val); } }; }); </code></pre> <p>displaystring.php</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;String Display&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;?php function displayString() { return "The string passed is: ".$_POST('string'); } displayString(); ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload