Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-29-2012, 05:01 AM   PM User | #1
jbrown1028
New Coder

 
Join Date: Sep 2006
Location: Fostoria, Ohio
Posts: 35
Thanks: 4
Thanked 0 Times in 0 Posts
jbrown1028 is an unknown quantity at this point
Ajax to PHP, strange issue

Hey Guys,
I have a strange issue that is going on here, and I am missing it. Let me lay down the example:

I have an index.php:
PHP Code:
    $postdata = isset($_POST['sysinfo']) ? $_POST['sysinfo'] : include('javascript.php');
   echo 
"Returned from Javascript :".$postdata."<br /><br />"
Basically this is testing POST['sysinfo'], if it is set, then it will equal the value and then it should display the results with the echo, if not it should include the javascript.php file.

javascript.php:
Code:
<script type="text/javascript" src="js/jquery.js"></script>
$.post("index.php", { sysinfo: 'HELLO WORLD'});
This file should load jquery, and send POST back to the index.php with sysinfo='HELLO WORLD'

Using Firebug, I see the POST data is this:
Returned from Javascript :HELLO WORLD<br /><br />

and the screen is blank, so basically it sent the POST back to the PHP file, although it is placing all of the file in POST, instead of just displaying it. Can someone point me in the direction of what I am doing wrong?

Thanks,
Jeff
jbrown1028 is offline   Reply With Quote
Old 06-29-2012, 08:42 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
$.post() is the method that executes the so called Ajax request which seems to run quite fine. But then your code fails to "do something" with the resulting output.
Code:
$.post("index.php", { sysinfo: 'HELLO WORLD'}, function(data) {
   // data contains the HTML output from the server script
   // show it inside an element on the current page with id="IdOfElement"
   $('#IdOfElement').html(data);
});
devnull69 is offline   Reply With Quote
Old 06-29-2012, 02:43 PM   PM User | #3
jbrown1028
New Coder

 
Join Date: Sep 2006
Location: Fostoria, Ohio
Posts: 35
Thanks: 4
Thanked 0 Times in 0 Posts
jbrown1028 is an unknown quantity at this point
That makes sense if I want to just display the data, although I want to work with it. With PHP, it data needs to be processed.

$parsedata = explode("|", $postdata);
# Gather all other collected data, and then add to database

There is where the problem is coming in at. Any thoughts?
jbrown1028 is offline   Reply With Quote
Reply

Bookmarks

Tags
ajax, passing variables, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:59 AM.


Advertisement
Log in to turn off these ads.