1

I am not sure why but jQuery is not passing parameters to PHP in order to complete the load() function with specific data based on the parameters ID.

In short term, when a user clicks a link there is onclick which fires up photo_tab('.$row['id'].');

account.php HTML element

<li><a href="#!/photos" onclick="photo_tab('.$row['id'].');"><i class="icon-camera"></i> Photos</a></li>

In a sence the ID should be passed to the photo_tab (the script is included into page not on the page it self)

general.js

function photo_tab(user_id) {
    $('.ac-content').load('ajax/photos.php',{user_id:id});
} 

And photos/ page should be loaded which is a PHP page and based on the user_id value load photos from database associated with that user_id.

<?php
   if ($_GET['user_id'] == 2) {
      echo "WORKED!";
   } else {
      echo "FAILED!";
   } 

***this is the photos/ file located at ajax/photos.php with mod_rewrite to point
otherwise to just photos/ or photos

EDIT: 1 - Using full path instead of rewrite photos > ajax/photos.php does not work 2 - The ID is being passed and echoed onto page via $row['ID']; 3 - ajax/photos.php is using $_REQUEST

4 Answers 4

1

Try passing the data as a query string, like so:

function photo_tab(user_id) {
    $('.ac-content').load('photos/','user_id='+id);
} 

EDIT: Giving this a second look, is that URL correct? It seems weird to have a relative URL.

You should also make sure the generated markup is correct, is the row ID printing out in the source?

EDIT 2: I set this up locally, this is working code, mimicking your file structure.

//localhost/account.php

<html>
<head>
    <script src="http://code.jquery.com/jquery.min.js"></script>
    <script>
        function photo_tab(id) {
            $('.ac-content').load(
                'ajax/photos.php',
                { 'user_id': id }
            );
        }
    </script>
</head>
<body>
    <div class="ac-content"></div>
    <a href="#!/photos" onclick="photo_tab(3);"><i class="icon-camera"></i> Photos</a>
</body>

//localhost/ajax/photos.php

<?php
if (isset($_GET['user_id']) && $_GET['user_id'] == 2)
{
    echo "WORKED!";
}
else
{
    echo "FAILED!";
}
Sign up to request clarification or add additional context in comments.

12 Comments

This could potentially work, but in this case there is no luck, its either the onclick is failing to trigger the photo_tab function or .load() is not working as it should
Yes, onclick="photo_tab(2);" 2 being my user ID from $row['id'] which is correct so the ID is being added to the href element which should use onclick to trigger the event, also I did change photos/ to ajax/photos.php still nothing
There's something wrong with that URL. Are you rewriting the URL? Edit: Just saw you are indeed. What's the URL of the page you're making the request from?
As I mention in other comments even using direct URL path does not work ajax/photos.php (<--actuall path) or photos/ or photos non work
That's a relative path. It depends on the current URL you're making the request from. If you're working from the root of the domain, try adding a slash at the beginning of it.
|
1

How about wrapping your variable in quotes?

function photo_tab(id)
{
    $('.ac-content').load('photos/',{'user_id':id});
} 

7 Comments

Nope, it looks like the .load() is not even bothering to process the URL its not even returning a FAILED! echo.
Try adding a function to see what kicks off after everything renders. function photo_tab(id) { $('.ac-content').load('photos/',{'user_id':id},function(r){alert(r)}); }
Nothing, no alert even being return. Ok this is very odd then
the photos folder resides on the same level as your jquery file? Maybe it cannot locate the folder?
actually even using direct path without re-write as ajax/photos.php still returns nothing
|
1

Yes parameters should not be passed as you supposed because as the name intends method load data from the server and place the returned HTML into the matched element.

.load( url [, data ] [, complete(responseText, textStatus, XMLHttpRequest) ] )

EG : Same as above, but will POST the additional parameters to the server and a callback that is executed when the server is finished responding.

$(".ac-content").load("photos.php", {user_id:user_id}, function(){
  alert("have been loaded");
});

Try the above syntax.

  1. Try $_REQUEST instead $_GET
  2. It should photos.php or some .php not photos/
  3. Make sure id is not null.

10 Comments

Nope nothing is being returned not even alert, also photos/ did work with a basic .load() without passing any values to it, so its not a problem even using photos/ direct path as ajax/photos.php did not do much nor changing $_GET to $_REQUEST
1 - Done (FAILED TO LOAD), 2 - Done (ajax/photos.php FAILED TO LOAD), 3 - Done ( onclick="photo_tab(2);" is being passed to page FAILED TO LOAD)
check updated answer. change user_id:id to user_id:user_id and check
let me know what's the outcome
it means photo_tab method is not accessible. general.js is not included correctly. make sure it's included correctly
|
0

Looks like id was never defined. Try this:

function photo_tab(id) {
  $('.ac-content').load('photos/',{user_id:id});
} 

2 Comments

Nope still no luck, its seems like the .load() part is not working and not loading into .ac-content div
I added a URL structure as well maybe that can solve few things, the function photo_tab is being loaded from general.js which wraps all things with $(document).ready(function() but I dough this is the issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.