Loading a form action inside a div - html

I have a form and I want to load the results from it into a div. I've already searched some topics about this and I thought that this one jquery submit form and then show results in an existing div would work but it doesn't.
This is my code so far:
<script type="text/javascript"> $('#form').submit(function() { // catch the form's submit event
$.ajax({ // create an AJAX call...
data: $(this).serialize(), // get the form data
type: $(this).attr('method'), // GET or POST
url: $(this).attr('action'), // the file to call
success: function(response) { // on success..
$('#test').html(response); // update the DIV
}
});
return false; // cancel original event to prevent form submitting }); </script>
<DIV id="test"></DIV>
<FORM id="form" name="pcc" method="post" action="http://wl.breedbandwinkel.nl/postcodecheck" onSubmit="return validatePcc(this);">
<div class="one_third firstcols">
<H4>Ik ben op zoek naar:</H4>
<DIV class="ff"><INPUT type="radio" class="pccrad radio" name="sub" value="alles-in-een-pakketten" id="pcc-alles-in-een-pakketten" onclick="$('#pcc-no').hide(); $('#pcc-fpcon').css('visibility', 'visible'); if($('#pcg').val() == '') $('#pcg').focus();"><LABEL class="left pcm" for="pcc-alles-in-een-pakketten" onmouseover="mpopup('Alles-in-één pakketten','Extra voordelig pakket met internet, digitale telefonie en/of digitale televisie.');" onmouseout="kill();">Alles-in-één pakketten</LABEL></DIV> <DIV class="ff"><INPUT type="radio" class="pccrad radio" name="sub" value="internet" id="pcc-internet" onclick="$('#pcc-no').hide(); $('#pcc-fpcon').css('visibility', 'visible'); if($('#pcg').val() == '') $('#pcg').focus();"><LABEL class="left pcm" for="pcc-internet" onmouseover="mpopup('Internet','Altijd supersnel onbeperkt online tegen een vast bedrag per maand.');" onmouseout="kill();">Internet</LABEL></DIV> <DIV class="ff"><INPUT type="radio" class="pccrad radio" name="sub" value="digitale-televisie" id="pcc-digitale-televisie" onclick="$('#pcc-no').hide(); $('#pcc-fpcon').css('visibility', 'visible'); if($('#pcg').val() == '') $('#pcg').focus();"><LABEL class="left pcm" for="pcc-digitale-televisie" onmouseover="mpopup('Digitale Televisie','Geniet van haarscherp digitaal beeld en geluid inclusief de gratis digitale programmagids.');" onmouseout="kill();">Digitale Televisie</LABEL></DIV>
</div><!-- end .one_third -->
<div class="one_third">
<H4>Mijn postcode en huisnummer zijn:</H4>
<TABLE border="0" cellspacing="0" cellpadding="0">
<TR>
<TD height="14" colspan="2">Postcode</TD>
<TD>Huisnr.</TD>
</TR>
<TR>
<TD width="51"><INPUT type="text" class="text" maxlength="4" size="5" value="" name="pcg" id="pcg" onKeyUp="autoTab(event,this,4,pcl);" onFocus="chBg(pcc,'pcg');" onBlur="chBg(pcc,'reset');" style="width: 41px;"></TD>
<TD width="46"><INPUT type="text" class="text" maxlength="2" size="2" value="" name="pcl" id="pcl" onKeyUp="autoTab(event,this,2,hn);" onKeyDown="backSpace(event,this,pcg);" onFocus="chBg(pcc,'pcl');" onBlur="chBg(pcc,'reset'); upperCase(event,this);" style="width: 26px;"></TD>
<TD width="36"><INPUT type="text" class="text" maxlength="6" size="4" value="" name="hn" id="hn" onKeyDown="backSpace(event,this,pcl);" onFocus="chBg(pcc,'hn');" onBlur="chBg(pcc,'reset');" style="width: 36px;"></TD>
</TR>
</TABLE>
<U class="dot small" onmouseover="popup('Waarom mijn postcode invullen?','Om te kunnen controleren welke abonnementen op uw adres leverbaar zijn hebben wij uw postcode en huisnummer nodig.<br>Uiteraard respecteren wij uw privacy. Deze gegevens worden niet opgeslagen.');" onmouseout="kill();">
Waarom mijn postcode invullen?</U>
</div><!-- end .one_third -->
<div class="one_third lastcols">
<INPUT type="submit" name="submit" value="Vergelijk de aanbiedingen op uw adres" class="button">
</div><!-- end .one_third -->
</FORM>
So I figured out that this is not working. I would really like to show the results from the action url (http://wl.breedbandwinkel.nl/postcodecheck) into <div id="test">.
Currently I'm doing this within an iframe but that just doesn't look "professional".
I hope I gave enough information, if not let met know.

Most importantly, if your Web page is not running from within http://wl.breedbandwinkel.nl, the AJAX call probably won't run at all due to most every browser disabling cross-site scripting. You can't make an AJAX request to foo.com from a page served from bar.com. To circumvent this, what I usually do is write a file such as "bar.com/ajaxActions.php" and then use that PHP script to make either the GET or POST request to the foreign site. Once it retrieves the result, I simply print that result to the standard output, which then becomes the result of your AJAX request.
The other thing I would do is ditch the "method" and "action" attributes in your <form> tag and put those in the AJAX request you're trying to write with jQuery. Use an onClick() listener in your submit button instead, as such:
<INPUT type="submit" name="submit" onClick="doAjaxRequest()" value="Vergelijk de aanbiedingen op uw adres" class="button">
Then in that function, use the code you already had in place for starters:
<script type="text/javascript">
function doAjaxRequest() {
$.ajax({ // create an AJAX call...
data: $("#form").serialize(), // get the form data
type: GET, // GET or POST
url: "ajaxActions.php", // the file to call -- postcodecheck if you're on that same domain, otherwise ajaxActions.php
success: function(response) { // on success..
$('#test').html(response); // update the DIV
}
});
}
Finally, if you're not on the same domain, I will leave it to you to find out the PHP code for the GET request (use file_get_contents()) or the POST request (use cURL). Or if you can't use PHP, then use your back-end language of choice. In PHP, assuming your post code checker accepted a GET request, your ajaxActions.php file would look something like this:
$response = file_get_contents("http://wl.breedbandwinkel.nl/postcodecheck?pcg=" . $_GET["pcg"] . "&pcl=" . $_GET["pcl"] . "&hn=" . $_GET["hn"] );
print $reponse;

Related

Best way ever to find the value in a HTML file?

hello.
I need help to find a token value in a HTML file.
</div>
<div class="nota"><input type="checkbox" id="desactivarComentario" name="desactivarComentario" /><label for="desactivarComentario">No deseo cargar comentarios para los informes. (modificable en Configuración)</label></div>
</div>
<input name="__RequestVerificationToken" type="hidden" value="XyPDNNtKIHJVg2xhyikMyUcwD26-T9z8HMEWiQh0KXq2vUjMahh2n-nL_fh6_bPJUupSiWc3fcvCdcz-ohZB-4K34WT0-PRXX-MsltnQI8mSYg81kzrFhvByJtLl36D-0" />
<div id="wrapper-resultado" class="cf ly-body">
<div class="cf barra-consulta">
<ul class="left">
<li class="fst">
In this case the value that i should obtain is:
"XyPDNNtKIHJVg2xhyikMyUcwD26-T9z8HMEWiQh0KXq2vUjMahh2n-nL_fh6_bPJUupSiWc3fcvCdcz-ohZB-4K34WT0-PRXX-MsltnQI8mSYg81kzrFhvByJtLl36D-0"
What is the best ever method to find it?
Thanks!
You could use jQuery and execute:
var val = $('input[name="__RequestVerificationToken"]).val();
You can use
var x = document.getElementsByName("__RequestVerificationToken")[0].value;
You can do this vía jQuery, see the code below:
https://jsfiddle.net/monodisco/hj7p8dne/6/
$(document).ready(function() {
var __RequestVerificationToken = $("input[name=__RequestVerificationToken]").val();
alert("__RequestVerificationToken IS ::: " + __RequestVerificationToken);
});

Opening an html to a div with XMLHttpRequest causes sync error

I am trying to load a htm to a div in another htm but I keep getting the error below:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
Here is my scenario:
First.html (html)
<div id="selectedPage"></div>
First.html (script)
<script>
function loadHTML2Div(htmlPage){
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
{
$("#selectedPage").html(xmlHttp.responseText);
}
};
xmlHttp.open("GET", htmlPage, true); // true for asynchronous
xmlHttp.send(null);
}
$(document).ready(function(){
loadHTML2Div("Second.htm");
});
</script>
Second.htm (html)
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class='jumbotron'>
<span>Verifique as datas disponíveis e agende seu evento.</span>
</div>
<div data-provide="calendar" id="calendar"></div>
</div>
</div>
</div>
<div class="modal fade" id="preReservaModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="modaldate"></h4>
</div>
<div class="modal-body ">
<div class="form-group">
<label for="exampleInputNome">Nome Completo</label>
<input class="form-control" id="exampleInputNome" placeholder="Digite seu nome completo" type="nome">
<br/>
<label for="exampleInputEmail1">Email</label>
<input class="form-control" id="exampleInputEmail1" placeholder="Digite seu email" type="email">
<br/>
<label for="exampleInputTelefone">Telefone para contato</label>
<input class="form-control" id="exampleInputTelefone" placeholder="Digite seu telefone para contato" type="telefone">
<br/>
<label for="exampleInputPlano">Pacote</label>
<select class="input-large form-control">
<option value="" selected="selected">Selecione um pacote</option>
<option value="DI" >Diamante</option>
<option value="ES">Esmeralda</option>
<option value="RU">Rubi</option>
</select>
</div>
</div>
<div class="modal-footer">
Fechar
Confirmar
</div>
</div>
</div>
</div>
<script src='bootstrap/js/bootstrap-combobox.js'></script>
<script src="bootstrap/js/bootstrap-year-calendar.js"></script>
</body>
I also have a navbar-nav from bootstrap on top of my First.htm for the navigation, and I also have a Third.htm and Fourth.htm that can be opened when the navbar is clicked. I use loadHTML2Div for switching between the contents of the . I don't know if this is the best approach.
As far as I searched this Synchronous XMLHttpRequest error, I would fix it by using ajax async call. I tried using xmlHttpRequest as mentioned above and I also tried using .ajax async
function loadHTML2Div(htmlPage){
$.ajax({
async: true,
type: "GET",
url: htmlPage,
success: function(data){
$("#selectedPage").html(data);
}
});
}
But I got the same error.
Please advise me how can I avoid this sync error. As you can see I tried different ways before elaborating this question.
If you need more information please let me know.
Edited
I kept testing and I fixed this error in some htmls. The problem was I was adding the Jquery and the bootstrap js in both First and Third html for example.
I removed the script declaration from the third.htm for example and left only the declaration in the 'upper' html (First.html). So somehow declaring it on both files was causing me the error.
Unfortunatelly, I still have a problem with the Second.htm which I copied to this question. This htm has a calendar and a bootstrap combobox. If I delete them from the Second.htm and write them in the First.htm, it doesn't work.
<script src='bootstrap/js/bootstrap-combobox.js'></script>
<script src="bootstrap/js/bootstrap-year-calendar.js"></script>
I also have some scripts for the clickDay and setMinDate in the Second.htm as shown below which fail if I remove the scripts declaration and move it to the upper First.htm.
$('#calendar').data('calendar').setMinDate(todayDt);
So it seems to me my lack of knowledge is leading me to this problem. It is probably very simple to solve it, if someone could help me i will appreciate.
set your the ajax attribute async to false
$.ajax({
async: false,
type: "GET",
url: htmlPage,
success: function(data){
$("#selectedPage").html(data);
}
});
I finally figured out what the problem was.
I moved the scripts declaration from Second.htm to First.htm
<script src='bootstrap/js/bootstrap-combobox.js'></script>
<script src="bootstrap/js/bootstrap-year-calendar.js"></script>
Then I changed my html from
<div data-provide="calendar" id="calendar"></div>
to
<div id="calendar"></div>
and created the calendar in the ready function
<script>
$( document ).ready(function() {
$('#calendar').calendar();
});
</script>
As I am a newbie in web development, I know this is still not the best way to structure my website navigation using navbar from bootstrap. For now I will leave this way.
My goal is to have my first htm with the navbar and the contents from each navbar item in different htms (as I have now), but I want the url to change as I click each item:
www.mywebsite.com/First.htm
www.mywebsite.com/Second.htm
www.mywebsite.com/Third.htm
And right now I only have
www.mywebsite.com/First.htm
Where all my scripts are included in the First.htm. It means I am loading the calendar.js even if I don't open the calendars page.
Well, I hope I will help someone with my question/answer in the future even though it is a little confusing. I promise next time I will have more knowledge.

html POST request login to website

Hi im trying to figure out how to login to a website using a post request.
I want to do this because i want to make a web app using particular data from content shown on the website after login.
However i cannot seem to figure out which url i need to use to login.
This is the FORM :
<FORM onSubmit="return checkrequired(this)" METHOD=POST ACTION="/pkmslogin.form">
<FONT SIZE="+2">
<TABLE BORDER="0" WIDTH="400">
<TR>
<TD ALIGN="LEFT"><UL><LI>Gebruikersnaam</LI></UL></TD>
<TD><INPUT TYPE="TEXT" NAME="username" SIZE="15" AUTOCOMPLETE="off">
</TD>
</TR>
<TR>
<TD ALIGN="LEFT"><UL><LI>Wachtwoord</LI></UL></TD>
<TD><INPUT TYPE="PASSWORD" NAME="password" SIZE="15" AUTOCOMPLETE="off"></TD>
<INPUT TYPE="HIDDEN" NAME="login-form-type" VALUE="pwd">
</TR>
</TABLE>
</FONT>
<BR>&nbsp <INPUT TYPE="SUBMIT" VALUE="Aanmelden">
The javascript checkrequired():
function checkrequired(which) {
var pass=true;
if (document.images) {
for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];
if (((tempobj.type=="text"||tempobj.type=="password")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==0)) {
pass=false;
break;
}
}
}
if (!pass) {
shortFieldName=tempobj.name.substring(0,30).toUpperCase();
if (shortFieldName=="USERNAME") {
shortFieldName="Gebruikersnaam";
}
if (shortFieldName=="PASSWORD") {
shortFieldName="Wachtwoord";
}
alert("Het veld \""+shortFieldName+"\" is niet ingevuld.");
return false;
}
else
return true;
}
I thought i needed to use /?Username='...'&password='...' but this is not the case.
edit
Chrome developer tools tells me no variables are being passed to the pkmslogin.form
Path = pkmslogin.form
method = POST
Status = 302 Moved Temporarily
type = text/html
Initiator = Other
Size = 713 B 0 B
Time = 367 ms 366 ms
It seems that you are using IBM WebSEAL but instead of using its management page, you made your own
So, the problem is that you are sending the request to /pkmslogin.form but as your application is behind WebSEAL, so it must be accessed by a junction.
So, your request actually goes to:
https://WebSEAL_HOST:WebSEAL_Instance_Port/Your_Junction/Your_App_Context_Root/pkmslogin.form
You have two solution:
Use a relative URL:
../../Your_Junction/pkmslogin.form
Use an absolute URL: https://WebSEAL_HOST:WebSEAL_Instance_Port/pkmslogin.form

Autofill on textbox (in Chrome) results in being prefilled without pushing enter

I have a very strange issue, that results in quite a lot of problems for our visitors.
On a normal textfield, Chrome (and other browsers) suggests strings to prefill. When you hover them and move the mouse away, they are not selected and written in the textbox.
However, in my setup, I have a weird case. When I hover my options, and then move the mouse it, it selects an item in the box. This results in an awful lot of "please enter an email" messages, while the user sees an e-mail on their screen.
See problem in this video:
https://www.youtube.com/watch?v=Vh2nb0_IR3Q
My markup for this particular e-mail:
<input type="text" name="Email" placeholder="E-mail" id="newUserEmail" class="email_input newinputtxt">
Does anyone have a hint? Because i am really lost...
EDIT:
Full ASP.NET MVC markup:
<asp:Content ID="Content1" ContentPlaceHolderID="plhMain" runat="server">
<h2>Indtast e-mail adresse</h2>
<div class="checkout__section checkout__section--login checkout_auth">
<div class="single_login">
<div id="newUserBox">
<div id="provideUserEmailBox">
<div class="email_auth">
<div>
<input type="text" name="Email" placeholder="E-mail" id="newUserEmail" class="email_input newinputtxt" />
</div>
<span class="red auth-error-text" style="display: none;" id="invalidEmailText">Der skal indtastes en gyldig e-mail</span>
<ul class="red_checkmarks" style="margin-top: 5px;">
<li>Vi bruger e-mail adressen til at sende en bekræftelse pa din ordre</li>
<li>Hvis du vil, kan du logge ind eller oprette en konto på næste side.</li>
</ul>
</div>
</div>
<div id="createNewUserBtnBox">
<input id="newUserBtn" type="button" class="button button--primary" value="Fortsæt" />
<span class="red auth-error-text" id="createNewUserErrorText"></span>
</div>
</div>
</div>
<div id="socialLoginList">
<button class="pfacebook" type="button" name="provider" value="facebook" title="Log ind med din Facebook konto">
Facebook
</button>
<button class="pgoogle" type="button" name="provider" value="google" title="Log ind med din Google konto">
Google
</button>
</div>
</div>
<script type="text/javascript">
$(function () {
$("#newUserEmail").keypress(function (event) {
if (event.keyCode == 13) {
event.preventDefault();
$("#newUserBtn").click();
}
});
var auth = CheckoutAuthorizationFlow({ LoginUserBox: "#loginWithUserBox", NewUserBox: "#newUserBox" });
auth.Init();
var facebookLogin = function () {
var loginUrl = '/login?returnurl=' + encodeURIComponent(document.location.href) + '&r=' + (new Date().toUTCString()) + '&provider=facebook';
//alert('facebook login');
document.location.href = loginUrl;
return;
};
var googleLogin = function () {
var loginUrl = '/login?returnurl=' + encodeURIComponent(document.location.href) + '&r=' + (new Date().toUTCString()) + '&provider=google';
document.location.href = loginUrl;
return;
};
$(".pfacebook").click(facebookLogin);
$(".pgoogle").click(googleLogin);
});
</script>
</asp:Content>
So my roommate, who has been working a bit with Wordpress a couple of years back, just came by my computer and said:
"Wrap it in a form tag!"
So I told him that was a horrible idea, and he said "try it".
And I did.
And it fucking worked.
So tl;dr -> wrap it in a form tag, and it works... I'll go cry.

Embedding a <div> from a external third party web page

I'm trying to show a div which contains a texbox and a button, in my web page.
the div is not in my server, is a third party web and I don't have access to modify the base code.
this is posible??? this is the code that I want to display in my web, from the third party web.
the div tag id is "body"
<div id="body">
<h2>Consulta de Teléfonos Robados o Bloqueados por IMEI</h2><div style="width:100%; height:auto;">
<script type="text/javascript">
function buscar(keyWords){
jQuery(document).ready(function($){
$.post('../../../bdtronline/sistema/areas.php',{
accion:'searchImei',
keyWords:keyWords},
function(data){$('#listImeiFound').html(data);});
});
}
</script>
<form>
Buscar <input type="text" id="keyWords" name="keyWords" size="50" /><input type="button" value="buscar" onclick="buscar(document.getElementById('keyWords').value);" />
</form>
</body>
If you have PHP running on the server your JavaScript runs at, you can load a page of your server, that takes the page content from the other domain via PHP:
proxy.php:
<?php
$opts = array('http' =>
array(
'method' => 'POST',
'header' => "Content-Type: application/x-www-form-urlencoded",
'content' => http_build_query($_POST)
)
);
$context = stream_context_create($opts);
echo file_get_contents('http://php.net/manual/en/function.file-get-contents.php', false, $context);
yoursite.html
// ...
jQuery(document).ready(function($){
$.post('proxy.php',{
accion:'searchImei',
keyWords:keyWords},
function(data){$('#listImeiFound').html(data);});
});
});
// ...