CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Ajax and Design (http://www.codingforums.com/forumdisplay.php?f=55)
-   -   Get PHP contents from JQuery (http://www.codingforums.com/showthread.php?t=247851)

q1h 01-04-2012 03:57 AM

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 ...

Dormilich 01-04-2012 12:32 PM

er, you’re already doing that.

q1h 01-05-2012 04:34 AM

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.

DanInMa 01-05-2012 04:44 AM

Quote:

Originally Posted by q1h (Post 1177348)
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");
});


Dormilich 01-05-2012 12:08 PM

Quote:

Originally Posted by q1h (Post 1177348)
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.

q1h 01-08-2012 07:31 PM

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 ...

_Aerospace_Eng_ 01-08-2012 07:57 PM

When do you trying binding to the click function? Before or after the page loads?

q1h 01-08-2012 09:07 PM

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");
    });


DanInMa 01-08-2012 09:22 PM

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");
    });
  });


q1h 01-08-2012 10:04 PM

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 ...


All times are GMT +1. The time now is 06:13 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.