There is some HTML code which appears on the page as the result of AJAX request/response. This HTML contains GET requests to another php script. Links containing this requests are not working while "real" HTML (added on the page manually) works normally.
When I open the page source with Ctrl+U I see empty div's (but they actually have HTML retrieved via AJAX) and the full-fledged HTML code added manually. Can't figure out how can I make the AJAX-retrieved links working.
This is how I try to form the HTML code which must be added to the page as the result of AJAX response.
<?php
//some selections from the database...
//all subsequent varibles are the members of $row = mysql_fetch_array($query) array;
$html_to_be_inactive =
'<li id="productID_' . $productID . '">
<a href=work.php?action=deleteFromBasket&productID=' . $productID . ' onClick="return false;">
<img src="images/delete.png" id="deleteProductID_' . $productID . '">
</a> ' . $productName . '(' . $totalItems . ' items) - $' . ($totalItems * $productPrice) . '</li>';
echo $html_to_be_inactive;
?>
And that is it, result of 'echo' appears on the page after successful AJAX request as the simple HTML, and it does nothing when I click the link.
I do not perform DOM 'append' methods as I'm not familiar with DOM yet. I can see all the elements mentioned in $thml_to_be_inactive but the link seems to be really inactive. Also this HTML is absent in the "Ctrl+U" output, I can see it only when I select "Inspect element" in the browser.
The HTML which was added manually operates the same items as usual, but I need AJAX-retrieved HTML to be working as well.
I suspect I need to perform some 'append' method via JavaScript or jQuery, but I don't know how to do it in a proper way.
Thanks.
You need to put your href in quotes.
onClick="return false;" will override the default action (go to href) of your link. You need to bind an other event to the link, or just remove `return false'.
Your links use relative paths.
You're probably inserting the HTML into a page in a different directory, breaking the relative paths.
If so, you need to switch to absolute paths.
Related
I am not sure why my text for the link is not visible on the page but, when I take my mouse to the area where I was expecting a link text then I am able to click that
blank area" and able to download correct file!
Here is the code structure:
<html>
<head>
some heading/styling link etc.
<body>
some code related to creating dropdown and populating it (form used)
<?php
if submit button is clicked then bunch of variables are populated and
user receives an email with result file. Ideally, I would like to be able
to display a result file link inside this php code.However, I don't know
if php allows to create a hyperlink. So, I was testing to create a link
outside php code. The php code does some python query.
exec("/path/to/python script that does query $var1 $var2 $var3 2>&1",
$output)
?>
<a href="/<?php echo $output[8] ?>"Link to query result</a>
</body>
</html>
So, the text "Link to query result" is nowhere visible but the link exists. What is happening here?
Anchor's opening tag misses '>'
Change
<a href="/<?php echo $output[8] ?>"Link to query result</a>
to
Link to query result
I am currently working on a semi dynamic page where I use some GET functionality to personalize it. I also echo the date a couple of places. At the bottom of this page, I would like to have a button that gives the visitor the option to download/open this page as PDF. Without the header. I have integrated DOMPDF, but I simply cant get it to work properly and need some help. I have tried a couple of things found here on Stackoverflow, with no success.
In basic, I need the whole page printed in the PDF, but it should not open when page is loaded. But triggered by the button. And then without the header (one spesific div). Is this possible?
<?php
require_once("dompdf/dompdf_config.inc.php");
$html =
'<html><body>'.
'<p>This is a test for '.
'<?php echo htmlentities(substr(urldecode($_SERVER["QUERY_STRING"]), 1)); ?> </p>'.
'<p>Thank you for reading.</p>'.
'</body></html>';
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("the_inquiry.pdf");
return true;
?>
<html>
<body>
<div class="shouldnotPrintToPDF">
Content.
</div>
<div class="shouldPrintToPDF">
Sensitive content.
Open or save as PDF
</div>
</body>
</html>
This is basically our one page presentation. And contains a lot of text, so I will not present all of that here. But in this way, I have to write the page twice, in $html = as well as inside the actual tag. And the PDF save/open option pops up right from the start, which it should not. I also wish to append the echo htmlentities part to the actual pdf-name.. is this possible? The PDF opens and contains what put into the $html = just fine. But not triggered by the link.
Update:
When i do exactly what you perform here, I get an error "The requested URL /inquiry.php&pdf=1 was not found on this server." I have the page I am trying to print in pdf on root level, but the DOMPDF is in /dompdf.. I dont know if that has anything to do with it?
Update:
When i edited the link, i get all this information up in a new page, like below.
[_parse_properties(margin:=1.2cm)(empty)_parse_properties]
[_parse_sections[section[_parse_properties(display:=-dompdf-page)
(counter-reset:=page)(empty)_parse_properties]#html#section]
[section[_parse_properties(empty)_parse_properties]#empty#section]
_parse_sections][_parse_sections[section[_parse_properties(display:=block)
(empty)_parse_properties]#div##map##dt##isindex#section]
[section[_parse_properties(empty)_parse_properties]#empty#section]
_parse_sections][_parse_sections[section[_parse_properties(page-break
-before:=avoid)(display:=block)(counter-increment:=page)
(empty)_parse_properties]#body#section]
[section[_parse_properties(empty)_parse_properties]#empty#section]_parse_sections]
[_parse_sections[section[_parse_properties(display:=block)(margin:=1em
0)(empty)_parse_properties]#p##dl##multicol#section]
[section[_parse_properties(empty)_parse_properties]#empty#section]_parse_sections]
[_parse_sections[section[_parse_properties(display:=block)(margin-left:=40px)
(empty)_parse_properties]#dd#section]
[section[_parse_properties(empty)_parse_properties]#empty#section]_parse_sections]
[_parse_sections[section[_parse_properties(display:=block)(margin:=1em
40px)(empty)_parse_properties]#blockquote#section]
[section[_parse_properties(empty)_parse_properties]#empty#section]_parse_sections]
[_parse_sections[section[_parse_properties(display:=block)(font-style:=italic)
(empty)_parse_properties]#address#section]
[section[_parse_properties(empty)_parse_properties]#empty#section]_parse_sections]
[_parse_sections[section[_parse_properties(display:=block)(text-align:=center)
(empty)_parse_properties]#center#section]
Do you have any idea what it might be caused by?
Breakthrough:
When I activated DOMPDF_DPI it actually opens as PDF, but now all of the text comes on first line of the second page of the PDF. Like, all the text comes out on top of each other. Also, when it opens the PDF, the ?&pdf=1 are included in the htmlentities query string, which looks very messy since it is supposed to be a personalized page as well as the PDF.
You can set dompdf to parse CSS #media queries for standard media types (screen, print, voice, etc.). By default dompdf parses the "screen" media type styles, but you can change this in the configuration file. See the DOMPDF_DEFAULT_MEDIA_TYPE configuration setting. Then you just need to pass the original URL querystring with an appended variable telling the page to render to PDF. If your original URL is something like the_inquiry.php?name=Joe then your PDF URL could be the_inquiry.php?name=Joe&pdf=1.
Your code would then look similar to the following:
<?php
ob_start();
?>
<html>
<head>
<style>
#media print {
.shouldnotPrintToPDF, .pdflink { display: none; }
}
</style>
</head>
<body>
<div class="shouldnotPrintToPDF">
Content.
</div>
<div class="shouldPrintToPDF">
Sensitive content.
Open or save as PDF
</div>
</body>
</html>
<?php
if ( isset( $_GET['pdf'] ) ) {
require_once 'dompdf/dompdf_config.inc.php';
$html = ob_get_clean();
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("the_inquiry.pdf");
}
?>
I have a page which includes details of the registered users.
Every html table includes 80-90 users.
For every user there is a $username variable.
I normally show their pictures in a table like the code below.
print "<a href=\"small-avatar-$username.jpg\" target=\"_blank\">
<img src=\"big-avatar-$username.jpg\">
</a>";
But the user can open images in a new tab. I want to show big avatars easily.
My first choice was lightbox-jquery. But because i use twitter-bootstrap in my site, i decided to use default bootstrap and jquery features.
I saw that there is "bootstrap-modals". When user clicks link, i don't plan to show anything more than i big picture.
I tried this:
print "<a href=\"#$username" data-toggle=\"modal\" class=\"img-modal\" >
<img src=\"small-avatar-$username.jpg\" ></a>";
print '</td>';
.
print "<div id=\"$username\" class=\"modal\">";
<img src=\"big-avatar-$username.jpg\">
print "</div>";
.
<script type="text/javascript" id="js">
$('#username').modal();
</script>
I suppose putting $('#username').modal();
for every user to my page will make HTML file huge.
But then I tried class name of anchor like this: $('.img-modal').modal();
But this didn't work.
What would you recommend in this situation?
I would recommend you to use a HTML5 Custom Data Attributes in your <a> tag to identify the username and keep your img-modal class.
"<a href="#myModal" data-username='".$username."' class="img-modal">...
Trigger the call to modal on click on .img-modal (you don't need the data-toggle="modal")
$('.img-modal').click(function(event) {
You can get the value of the username by using
var username = $(this).attr('data-username')
Since you have the username you can replace the src property of your <img> tag in your unique modal with something like.
$("#img-in-modal").attr("src","big-avatar-" + username + ".jpg")
And open your modal
$('#myModal').modal('show')
And finally, make sure bootstrap-modal.js or boostrap.js is included.
I have a form that inserts data into mySQL. It works fine.
After the submission, I have a success page that displays 'part_no'. I need to also show 'add_qty', as well.
How do i alter my post script to show two field data's on the success page?
Here is part of my code (that already works):
$part_no = $_REQUEST['part_no'] ;
header("location: inv_fc_add_success.php?part_no=" . urlencode($part_no));
}
else {
header("location: inv_fc_add_fail.php");
}
?>
Just append it as another $_GET variable i.e part_no="part"&quantity=1
header("location: inv_fc_add_success.php?part_no=" . urlencode($part_no)."&qty=".$quantity );
You need 3 things.
First, you'll need:
$add_qty = $_REQUEST['add_qty'];
Alternatively you can simply use $_REQUEST['add_qty'] directly instead of assigning it to a new variable ($add_qty).
Then instead of:
header("location: inv_fc_add_success.php?part_no=" . urlencode($part_no));
you need:
header("location: inv_fc_add_success.php?part_no=" . urlencode($part_no) . "&add_qty=" . urlencode($add_qty));
Then, on the page inv_fc_add_success.php (which you will need to edit), you display the variable the same way that you display $part_no. As always, you can either assign it to a variable, like you already do at the top, or you can just use $_REQUEST['add_qty'] directory.
I'm creating a sample website using xhtml with javascript support. Also using php for server side programming. I need to redirect the webpage to some other page from an html page, after checking some condition.What is the best method to implement this. I've done it using
header("link"); but since i'm using it inside the tag, it shows up a error. is it possible to redirect to a particular link from within the tag.
The best way would be using PHP. Javascript solutions only work when… well, when javascript is enabled.
<?php
if($do_redirect) {
header("location: http://www.google.de");
}
?>
Note that this only works, when there was absolutely no output so far.
It depends on what the condition is.
If it is something you can test for in PHP, then do it in PHP (as one of the very first things you do, before you start thinking about generating output to the browser):
<?php
if (condition()) {
header("Location: http://example.com/foo/bar/baz");
exit();
}
?>
If it is something you can test for only in JavaScript then:
<script type="text/javascript">
if (condition()) {
location = "http://example.com/foo/bar/baz";
}
</script>
… keeping in mind the principles of progressive enhancement.
Sure. Do it through javascript:
window.location.href = 'http://www.google.com'
From within a tag you can use something like this
<tag onclick="if(condition == true) window.location.href = 'http://mylocation.com/'>Tag text</tag>
Most HTML tags support the onclick event, so replace tag with the type of tag you need for your situation.
The condition part can be an inline code to find some value, or some Javascript function you defined earlier.
try this
<?php
.
.
//your php code here
.
.
if($condition){
?>
script type='css/javascript'>
window.location.href = 'http://domain.com'
/script>
<?php
} else{
.
.
//again your php code here
.
.
}
?>