Jump to content

Multiple pages - calling a script function from another page


aubake01

Recommended Posts

Ok, this is my first post and it's kind of long, so bear with me...

I have these php pages. One is the user info page which loads tables of the user's info. The table data is generated by functions located in another file. The user has the option of editing their info which brings up a popup window that contains the editing page. Once the editing is done, the window closes. I would like the user info page to then automatically refresh the table that has just been edited. Currently I have a test button on the user info page that calls a jquery script and refreshes the appropriate table. This works fine, but it is manual, and I would like it to be done automatically. I tired including the user info page on the editing popup page and then calling the script when the user clicks the save button, but it  says the function is undefined. If I put the script code on the popup page, then the tables and divs are undefined. So I need help getting this to work. I'm not sure how to do this. I'm pretty new to all of this. I think maybe an ajax call from the popup page telling the user info page to update the table would work, but I'm not sure how to do that. Any ideas or thoughts on how to fix this problem supported with sample code would be extremely helpful!!! Let me know if this is confusing or if I need to add more details.

Thanks in advance!!!

Link to comment
Share on other sites

You're having a problem with scope.  Yes, you'll need to use AJAX.  There are tons of tutorials on this throughout the web.  When you get stuck, let us know. 

 

Essentially,  You're going to need to send your edits through ajax to a script that will modify the user's information.  The "save" button on the popup is merely to initiate the ajax request with the updated fields.  You need to set up a response in the receiving script to tell the pop-up JS the edits were successful.  Upon this response, the window can close.  However, i do not believe that you'll be able to fire a new request from another pop-up window.  However, using modal boxes you will not lose scope.

Link to comment
Share on other sites

Is there a way to do that with jquery? I have head that jquery makes ajax calls much more simple which would be great for someone like me. What I would like is when the 'edit' button is clicked on the main page, it sends a request to the popup window, opens the popup window, and waits for a response. Then the popup window gets the call and waits for the user to finish editing their content. When they click 'save', the request is sent back to the main page and the window closes. The main page receives the request and knows to reload the table data. Would that be possible with jquery? Could someone point me in the right direction? I have looked at a couple ajax tutorials as well as jquery tutorials, all basic and none sending calls to different pages so I am not sure how to start.  Thanks again!!!

Link to comment
Share on other sites

No, I was talking about the actual files needed to use modal box, like the prototype.js, scriptaculous.js, and modalbox.js.  Can you use modal box without physically having these files on your server, such as including a web library like you can do with jquery with the 'src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"' code? Is that possible do you know?

Link to comment
Share on other sites

All files referenced in the HTML header can be stored on external servers, though it is normally not recommended.

Not only will it increase the page response time quite significantly, but you're also at the mercy of these third party servers being up and running at all times. Not to mention the fact that the files themselves could be changed at any time, rendering your page inoperative without any action from you or your visitors.

 

So, yes: It is possible, but it is highly recommended to store the files locally.

Link to comment
Share on other sites

OK, thanks! I was just asking because the server I am using isn't my own personal machine, and I didn't have permissions to upload new files, just edit pre-existing ones. So I talked to the guy and he put the files on there for me so I am good to go. Now I just need to get it to work...

Link to comment
Share on other sites

Hey thanks Mahngiel for that last example. That is pretty much what I need. But is it possible to load another php that contains a form instead of a form on the same page via a div tag? If so, how would you do that and also pass it some variables, for instance $userid, $session, etc.?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.