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 01-04-2012, 03:57 AM   PM User | #1
q1h
New Coder

 
Join Date: May 2011
Posts: 34
Thanks: 7
Thanked 0 Times in 0 Posts
q1h is an unknown quantity at this point
Get PHP contents from JQuery

I can use the following JQuery function to return PHP results after a form submission:

Code:
    $(".some_class").bind("submit", function () {
        $.ajax({
            type: "POST",
            cache: false,
            url: "some_file.php",
            data: $(this).serialize(),
            success: function (data) {
                $('#php_results').html(data)
            }
        });
        return false;
    });
Is there a way to get PHP results without submitting a form? Thanks ...
q1h is offline   Reply With Quote
Old 01-04-2012, 12:32 PM   PM User | #2
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,882
Thanks: 9
Thanked 291 Times in 287 Posts
Dormilich is on a distinguished road
er, you’re already doing that.
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Old 01-05-2012, 04:34 AM   PM User | #3
q1h
New Coder

 
Join Date: May 2011
Posts: 34
Thanks: 7
Thanked 0 Times in 0 Posts
q1h is an unknown quantity at this point
Thanks for your reply. I'm trying to display the contents of a PHP file in a div (#results) without submitting a form. The above code uses a form submission.
q1h is offline   Reply With Quote
Old 01-05-2012, 04:44 AM   PM User | #4
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
Quote:
Originally Posted by q1h View Post
Thanks for your reply. I'm trying to display the contents of a PHP file in a div (#results) without submitting a form. The above code uses a form submission.
how do you want to trigger it? on page load? on a click event? on a timer? also without the form your not submitting any query. if you just want to load a simple php file then:

Code:
$('#php_results').load("somefile.php");

//or on document ready when the dom loads it will happen
$(document).ready(function(){
$('#php_results').load("somefile.php");
});
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users

Last edited by DanInMa; 01-05-2012 at 04:58 AM..
DanInMa is offline   Reply With Quote
Old 01-05-2012, 12:08 PM   PM User | #5
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,882
Thanks: 9
Thanked 291 Times in 287 Posts
Dormilich is on a distinguished road
Quote:
Originally Posted by q1h View Post
The above code uses a form submission.
nope. though you hook in on the form’s submit event, you cancel the form submission on the last line.

and if it were indeed submitting the form, the AJAX call would be pointless because when the response comes back, the handling JS code is gone due to the (re)load.
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Old 01-08-2012, 07:31 PM   PM User | #6
q1h
New Coder

 
Join Date: May 2011
Posts: 34
Thanks: 7
Thanked 0 Times in 0 Posts
q1h is an unknown quantity at this point
Yeah, I was trying to bind a link to the function. I tried this:

Code:
$(".refresh").click(function(){
        $('#results').load("data.php");
    });
But it doesn't work. Did I do something wrong? Thanks ...
q1h is offline   Reply With Quote
Old 01-08-2012, 07:57 PM   PM User | #7
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
When do you trying binding to the click function? Before or after the page loads?
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
_Aerospace_Eng_ is offline   Reply With Quote
Old 01-08-2012, 09:07 PM   PM User | #8
q1h
New Coder

 
Join Date: May 2011
Posts: 34
Thanks: 7
Thanked 0 Times in 0 Posts
q1h is an unknown quantity at this point
I'm trying to do it after the page loads (otherwise I would just reload the page via js). I've also used:

Code:
$(".refresh").live("click", function () {
        $('#results').load("data.php");
    });
q1h is offline   Reply With Quote
Old 01-08-2012, 09:22 PM   PM User | #9
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
perhaps this then. also if data.php needs some information posted to it to return a result, this is not good enough becuase you are nto capturing and sending any data to data.php

Code:
$(document).ready(function(){
$(".refresh").live("click", function () {
        $('#results').load("data.php");
    });
  });
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Old 01-08-2012, 10:04 PM   PM User | #10
q1h
New Coder

 
Join Date: May 2011
Posts: 34
Thanks: 7
Thanked 0 Times in 0 Posts
q1h is an unknown quantity at this point
Yea, I've tried that as well. My php file echoes lorem ipsum for testing - maybe I have another conflicting script running. Thanks for the replies ...
q1h is offline   Reply With Quote
Reply

Bookmarks

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 09:47 AM.


Advertisement
Log in to turn off these ads.