javascript submit is not working in https.
javascript code
function apply()
{
document.fileinfo.action='<%=uploadJSP%>';
// uploadJSP = https://localhost/upload.jsp
document.fileinfo.submit();
}
html code
<form name="fileinfo" action="upload.jsp" enctype="multipart/form-data" method="post">
...
</form>
result of newtwork capture on IE developer tool,
...
DOMContentLoaded (event) + 184ms -
Load (event) + 197ms -
on Load(event) break
This code is working normally on http (uploadJSP = http://loaclhost/upload.jsp)
I don't know what is wrong.
please advice for me to solve this problem
Firstly,
Have you tried printing the value of document.fileinfo.action in your first snippet after it has been assigned = "<%=uploadJSP%>"?
<%= {code} %> is only processed when the server sends html documents, so if your script is in a separate file from your html, or your server doesn't process code in between <script> tags, then document.fileinfo.action = "<%=uploadJSP%>" instead of document.fileinfo.action = "https://localhost/upload.jsp" as intended.
Second, you don't need to set the action for the form again in javascript since it's already set in html. So, instead of worrying how you can pass the correct value in your first snippet, I would suggest removing the document.fileinfo.action = "<%=uploadJSP%>" line altogether.
Related
I already searched and tried all the question and answers that are almost the same as my question in stackoverflow. Unfortunately, none of them provided what I needed which probably mine is a different situation.
I want to call a php function from another php page when the index.php page is loaded or refresh only.
There is a query in my php function that check the query then insert records whenever index.php is loaded. Anyone understood my problem?
My code below on the body onload does not perform the queries in the function
<body onclick="check();" onfocus="check();" onload="<?php include_once("includes/classes.php"); $empinfo = new EmployeeInfo(); $netsalary= $empinfo->getNetSalary($curr_emp); ?>" >
while my code below on the body onload. the insert query worked since it is direct to the onload not on the class.php page
<body onclick="check();" onfocus="check();" onload="<?php mysql_query("insert into tblNotifications (empCode, notifMsg, payMonth, payYear, notifRead, notifResolve, dateTime)
values ('$empCode', '$notifMsg', '$smonth', '$year', 0', '0', '$now')"); ?>" >
Please confirm first before voting negative or saying it's a duplicate. I also need a positive votes since I'm a noob.
Thank you in advance.
You are implicitly calling PHP script using javascript's onload which is not possible as javascript is client side where as PHP runs on server. Try to use AJAX or there is one method which may help:
Use javascript to write php scripts and wrap it in function before onload call.
document.body.onload = function writePHPscript(){
document.getElementById('id-here').innerHTML = "<?php echo 'hello!'; ?>";
};
(It is necessary to put everything in function you call after onload or it gets return value sometimes)
This should be really simple, so, either I am over thinking it or making it more complicated than it should be.
I would like to update a DIV without having to reload the webpage.
A form on Canvas.asp queries the database and returns the coordinates of a GPS device. The coordinates are updated every minute and would like the script to return the latest coordinates without having to refresh the page. The coordinates are appended to a separate XML file.
I have written this;
<script type="text/javascript">
$(document).ready(function() {
$("#map").load('canvas.asp');
var auto_refresh = setInterval(function() {
$("#map").load('canvas.asp?std=<%=session("7digit")%>&submit=Search&execute=1');
}, 60000);
$.ajaxSetup({ cache: false });
});
</script>
The div to be reloaded;
<div id="map"></div>
The script returns an error by duplicating the header and content, after 60 seconds the map DIV is nowhere to be seen... Simply disappears! The coordinates are appended to the XML file every 60 seconds, even after the error.
What am I doing wrong?
Looks like you are always returning the full result of your canvas.asp page which will always be a full HTML document which will not play nice with your <div>.
The issue here is how you handle passing partial content back and that comes down to how you structure your ASP page. Here is a bare bones template I use often for this type of thing.
<%
Option Explicit
Dim action, def_action
Const BASE_ERROR_VAL = 1000
Const DISPLAY_PAGE = 0
Const DISPLAY_CANVAS_CONTENT = 1
'Without this the page does nothing, this is the gateway to your page.
Call init()
'First code that get's run when page is requested
Sub init()
'Defaults
def_action = DISPLAY_PAGE
'Process query string
action = Request.QueryString("a") & ""
If Len(action) > 0 and Isnumeric(action) then action = CInt(action) Else action = def_action
Select Case action
Case DISPLAY_PAGE
Call load_page()
Case DISPLAY_CANVAS_CONTENT
Call load_canvas()
Case Else
'As we have a default this should NEVER happen, but always worth covering your bases.
Call Err.Raise(vbObjectError + BASE_ERROR_VAL + 1, "canvas.asp", "Action required")
End Select
End Sub
Sub load_page()
>%
<html>
<head>
...
</head>
<body>
<% Call load_canvas() %>
</body>
</html>
<%
End Sub
Sub load_canvas()
%>
<canvas>
...
</canvas>
<%
End Sub
%>
This is purely bare bones and is just designed to give you an idea of how you could approach it, so for example to call just the canvas part of the HTML you would use something like
canvas.asp?std=<%=session("7digit")%>&a=1
and either not pass &a at all (as DISPLAY_PAGE is the default) or pass
canvas.asp?std=<%=session("7digit")%>&a=0
to display the whole HTML.
You might also noticed I included
<% Call load_canvas() %>
inside the load_page() procedure, this is just for the situation where you might want the content of the canvas also rendered on the full pass and then changed later on via a partial pass using a=1 for example.
While the answer provided by #Lankymart demonstrates the desired page template and the correct layout of code which enables greater flexibility, the answer is a simple Ajax function.
setInterval(ajaxRequest, 15000);
function ajaxRequest() {
$.ajax({
type: 'GET',
url: 'xmlUpdateScript.asp',
data: {
7digit: "<%=session("7digit")%>"
}
});
}
The Ajax request executes the 'xmlUpdateScript.asp' and returns the next set of coordinates which are placed inside the XML document and can be rendered to the map.
Im trying to do something that should be very simple yet my head is about to explode considering I cannot get it to work.
In my asp.net MVC app, I make an Ajax call to the server, and the server sends back a message (as a string), which includes a link.
The message basically looks like this : Action failed, Learn more..
I am inserting this returned message in a div that shows the alerts from the server.
However, whatever I try, the 'Learn more.' part will never be inserted.
If I do alert(returnedMessage), it shows the correct html, but as soon as I do
$(mydiv).html(returnedMessage), the anchor-tag is gone. I tried unescaping, normal jscript innerHtml...not sure what I'm missing.
Thanks!
**UPDATE with some extra code **
I have the ajax call that returns a message. I have a method that then sets the message into the div and shows the alert.
the ajax call handling:
success: function (result) {
if (result.Message) {
showAlert(result.Message);
}
},
The javascript:
function showAlert(message) {
// neither setting the actual div, nor the span works
alert(message);
$('#server-message').html(message)
//$('#server-message span').html(message);
$('#server-message').fadeIn(100);
};
the html:
<div id="server-message">
<span></span>
</div>
also worth trying if you are escaping the double quotes properly :)
var returnMessage = 'Learn more.';
You should your message to .html() function $(mydiv).html(returnedMessage) if you doing $(mydiv).html = you only overwriting html property in this object.
I have an asp.net page and when a textbox is empty I need to hide the whole page from code behind. The problem is I have javascript and jquery code that is executed on document ready and gets data from some page controls and since the controls are not rendered this code fails and throws an exception.
At code behind i hide the whole page
// allPageTable is an html table
// with runat=server
this.allPageTable.Visible = false;
At Javascript I check if a textbox is null, if not so I run the code, else i don't. But mytxt is not defined so it enters into the if and fails.
if ($('#myTxt') != null) {
// My JQUERY / JS CODE
var data = $('#anotherTxt').val(); // Fails cause anotherTxt is not rendered
}
So I need a way to avoid javascript execution when the page is not rendered.
The selector $('#myTxt') will not return null when you control with id, myTxt, does not exists. You need to check the length of object returned by selector.
if ($('#myTxt').length > 0) {
// My JQUERY / JS CODE
var data = $('#anotherTxt').val(); // Fails cause anotherTxt is not rendered
}
First of all, You need this script executed on "documentReady", "onLoad" is not so necessary. To check if checkbox exists or not, You can use $('#myTxt').length > 0 because everything which is returned from jQuery selector mechanism is represented in array of elements, even if its one html element.
$(window).load executes after everything is loaded and html page has been rendered with css included. If your script will work on windows load then you'll obtain some "blink" effect. (disappear after everything is rendered)
var i = 0;
var interval = setInterval(function () {
i = i + 1;
if(typeof($('#myTxt')) != 'undefined') {
// do your stuff
clearInterval(interval);
}
}, 1000);
Don't if it's best approach, maybe someone else will post better one...
You could place your javascript code inside a Placeholder control and then set the visibility of that control the same way you set it for the html table. This way your script will not end up on the page. It needs some extra care to avoid "broken usages" of functions/variables but it's a general solution.
<table id="allPageTable" runat="server">
...
</table>
<%= "<script type=\"text/javascript\" language=\"javascript\">" %>
<asp:PlaceHolder runat="server" ID="PlaceholderJS">
javascript code here
</asp:PlaceHolder>
<%= "</script>"%>
.
this.allPageTable.Visible = PlaceholderJS.Visible = false;
Given the following code on an ASP.NET MVC View:
<% using (Ajax.BeginForm("AddCommunity",
new AjaxOptions { UpdateTargetId = "community-list",
OnSuccess = "BindCommunityHover" }))
{ %>
Add Community: <input type="text" id="communityName" name="communityName" />
<input type="submit" value="Add" />
<% } %>
And the following JavaScript method in the file:
function BindCommunityHover() {
$(".community-item-li").hover(
function () { $(this).addClass("communityHover"); },
function () { $(this).removeClass("communityHover"); }
);
};
Is there any reason why BindCommunityHover is not being called when the AJAX result comes back?
The community-list div is properly updated (the action returns a partial view). I have also tried setting OnComplete (instead of OnSuccess) to no avail.
The BindCommunityHover method is called in a $(function(){...}); block when the page first loads, and for all existing .community-item-li elements, it works.
The partial result from my controller replaces all items in that div with more of the same class. The OnSuccess method is supposed to fire after the document is updated.
Update: k...this gets weird. I added the following to the BindCommunityHover method:
alert($(".community-item-li").size());
I'm getting 240 in the alert when the page loads and when the callback fires. So, the callback IS firing, jQuery is matching the elements but not applying the styles...
That's because your function is basically saying add a hover event for all of these items as they exist at the point in time when the function is called.
If you then add new elements they aren't automatically bound. There is a new feature in JQuery called Live Events. I've not dug into them but I think they might help here. Otherwise as you add new elements be sure to bind the hover functions.
Okay, there were two parts to this solution.
First culprit was some nasty caching thing that I can't figure out in Cassini/IE. I tried rebooting, stopping Cassini, restarting VS2010...nothing worked.
The code still won't work on IE on my account on this computer. The deployed-to-IIS version works on all browsers. It also works in IE if I change the filename. Something is borked there, though. If I run the project with Cassini/IE, then open FireFox and go to the site, it works.I tried to repro the error to file a bug, but I can't get it to go. I digress. To get around this I changed the name of the .js file and moved the reference to a different spot in the master page.
The other thing was that I did have to use OnSuccess. I switched to using OnComplete when I was trying to figure out what was wrong. After I figured out the file/browser/server problem, I realized that OnComplete (per the docs) fires before the document is updated; the elements were being updated but then thrown away.
The OnSuccess/OnComplete might help sort something out for someone, not sure about the file/browser/server issue...that might be environmental.