• Post Reply Bookmark Topic Watch Topic
  • New Topic

Fetch data from Mysql in jquery magnific Popup

 
shivam singhal
Ranch Hand
Posts: 231
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello all..
I am developing my college's project in JSP using jquery to open a magnific popup when user clicks on a link and the in the magnific Popup must be fetched from Mysql and i tried two approaches for this:

1. magnific Popup type is ajax
here i passed the variabe value in the link of href (after '?') to another JSP page where connection to database is created and queries are written in JSTL to fetch data and show this in magnific Popup ..
But i failed in this approach, don't know in another JSP page the data without having database connection is loaded in the magnificPopup easily but not database data.. :(

2. magnific Popup type inline
here i need to pass the variable value in the same page between different tags.. don't find this approach good..

so, any solution for the same.??
please help..
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Serve the data from a servlet instead and call that servlet using AJAX
 
shivam singhal
Ranch Hand
Posts: 231
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks E Armitage..

Actually i tried this too, in my 1st approach..
using ajax type magnific popup..
may be i implemented in wrong way..

can you please provide an example about how to call servlet using Ajax?
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You said you tried fetching the data from a JSP with queries written in JSTL which is different (and shouldn't really be done). There are many examples online of how to use AJAX to make a server side call.
I suggest you break it down.
1.) Make a class that fetches the required data given the right parameters.
2.) Test that class and make sure it works as expected.
3.) Then write the servlet and make it use that class to fetch the data.
4.) Make sure you can access the servlet on the url influenced by the mapping you configured in the web.xml
5.) Make an ajax call to the servlet from the JSP
 
shivam singhal
Ranch Hand
Posts: 231
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok,,
why we can not fetch the required data with right parameters in servlet?
 
shivam singhal
Ranch Hand
Posts: 231
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
on little google i saw this..


to connect to server side using Ajax/jquery , but i am using this for magnific-popup


so, i think we need to connect to server side within this popup?
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shivam singhal wrote:
why we can not fetch the required data with right parameters in servlet?

Because that would mix JDBC and javax.servlet APIs in one class making it difficult to test the one without worrying about the other and making it impossible to reuse your database access code.
shivam singhal wrote:
so, i think we need to connect to server side within this popup?

You can but you don't have to. You should see the docs for that plugin so see the different ways of using it. You can have a div with your popup layout and make the AJAX call before loading the popup. The AJAX call would use javascript to set the values on the controls that will be displayed within the popup.
The ajax mode for the popup is for loading all the popup content (including html layout) via AJAX. You would have to see their docs to see how to provide the url for the popup but some people like to keep all their HTML in JSPs and only send data from the server, not html. That way, the same server side code can be used for multiple types of front-end clients.
 
shivam singhal
Ranch Hand
Posts: 231
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<a href="javascript:promote(${data.PKey});" data-mfp-src="#erra" class="open-popup-link">

now, as you directed me yesterday, i have created a javascript to call ajax to server side, they all are running perfectly only when i removes the class from anchor tag,
here class in the anchor is used by magnific popup..

i.e if i removes magnific popup it works fine, but with magnific popup, it is not displaying content in the popup??
is it like when magnific popup is present, the control is unable to go to javascript???
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!