We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,668 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Result from $.post call is source code of page???

I am trying to call a .php or .html file to display an input page for emails.

The file ContactDisplay.php contains a <button> to onclick a call to the sendEmail() function which, in turn, sends data to the file ContactEmail.html. The data is retrieved using $_POST and used to populate the <form> contained in ContactEmail.php.

Please see attached file.

The problem is: The form is not displayed nor is the result of print_r($_POST). The 'response' area of FIREBUG shows the total source code of the ContactEmail.php file.

I suspect this is the result of some stupid thing I've done but would appreciate some help in resolving the problem.

Thanks in advance, RP

Attachments email_problem.html (3.15KB)
2
Contributors
4
Replies
19 Hours
Discussion Span
1 Year Ago
Last Updated
5
Views
pizzipie
Newbie Poster
20 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Just posting to a PHP file doesn't show that page. The post function has a callback, which used, gives you the result of the page you post to. Then you can use Javascript/jQuery to do something with that. Have a look at the examples in the manual.

pritaeas
Posting Prodigy
Moderator
9,549 posts since Jul 2006
Reputation Points: 1,194
Solved Threads: 1,497
Skill Endorsements: 98

I'm confused (again).

In looking at the manual it givesa number of examples at least two of which imply that you don't need to have a callback function.

Examples: (from manual)

Example: Request the test.php page, but ignore the return results.

$.post("test.php");

Example: Request the test.php page and send some additional data along (while still ignoring the return results).

$.post("test.php", { name: "John", time: "2pm" } );

Example: pass arrays of data to the server (while still ignoring the return results).

$.post("test.php", { 'choices[]': ["Jon", "Susan"] });

Example: send form data using ajax requests

$.post("test.php", $("#testform").serialize());

Example: Alert out the results from requesting test.php (HTML or XML, depending on what was returned).

$.post("test.php", function(data) {
alert("Data Loaded: " + data);
});

Example: Alert out the results from requesting test.php with an additional payload of data (HTML or XML, depending on what was returned).

$.post("test.php", { name: "John", time: "2pm" },
function(data) {
alert("Data Loaded: " + data);
});

Example: Gets the test.php page content, store it in a XMLHttpResponse object and applies the process() JavaScript function.

$.post("test.php", { name: "John", time: "2pm" },
function(data) {
process(data);
},
"xml"
);

If I use a callback function like:

function () {

pizzipie
Newbie Poster
20 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

that's supposed to be:
function () {
return true;
}

Sorry, haven't found out how to edit this post.

R

pizzipie
Newbie Poster
20 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Example: Request the test.php page, but ignore the return results.
$.post("test.php");


That is what you do, so anything that is echoed by the PHP file is ignored.

pritaeas
Posting Prodigy
Moderator
9,549 posts since Jul 2006
Reputation Points: 1,194
Solved Threads: 1,497
Skill Endorsements: 98

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0702 seconds using 2.68MB