Jquery ajaxForm() doesn't fire 'success' although it works successfully - javascript

Today I was trying to send files via Ajax request using the JQuery AjaxForm plugin. However, it doesn't fire the success function as it uploads the file without any javascript run time or compile time error.
Here is my code:
<table id="haberresmiekle">
<form action="action.asp?kmt=resimyukle" method="post" enctype="multipart/form-data" id="haberresmiekleform">
<tr>
<td><input type="file" name="file"></td>
</tr>
<tr>
<td><input id="b" type="submit" value="Gonder"></td>
</tr>
</form>
</table>
and
<script>
$("#haberresmiekle").dialog({autoOpen:false,title:"Resim Yukle"});
var options={
target:"#haberresmiekle",
success:function(){alert('x');$("#haberresimekle").dialog('close');}
};
$("#haberresmiekleform").ajaxForm(options);
$("#b").button();
</script>
Thanks for any help
Note: It has been resolved.

Yor script will do nothing(except in IE) as long as you dont use valid selectors.
$(haberresmiekleform)-> $('#haberresmiekleform')
$(haberresmiekle) -> $('#haberresmiekle')
$(button) -> $('#button')

Related

Submitting a Form using Selenium in Python

I need to scrape some data behind those hyperlinks from this Site. However, those hyperlinks are javascript function calls, which later submits a form using post method. After some search, selenium seems to be a candidate. So my question is that how should I properly set a value to an input tag and submit the form which does not a submit a button.
from selenium import webdriver
url = "http://www.echemportal.org/echemportal/propertysearch/treeselect_input.action?queryID=PROQ3h3n"
driver = webdriver.Firefox()
driver.get(url)
treePath_tag = driver.find_element_by_name("treePath")
Before submitting the form, I need to assign value to tag <input>. However, I got an error
Message: Element is not currently visible and so may not be interacted
with
treePath_tag.send_keys('/TR.SE00.00/QU.SE.DATA_ENV/QU.SE.ENV_ENVIRONMENT_DATA/QU.SE.EN_MONITORING')
IF above is correct, I would like to submit form this way. Is it correct?
selenium.find_element_by_name("add_form").submit()
Below are sources from the web page.
JavaScript function
<script type="text/javascript">
function AddBlock(path){
document.add_form.treePath.value=path;
document.add_form.submit();
}
</script>
form "add_form"
<form id="addblock_input" name="add_form" action="/echemportal/propertysearch/addblock_input.action" method="post" style="display:none;">
<table class="wwFormTable" style="display:none;"><tr style="display:none;">
<td colspan="2">
<input type="hidden" name="queryID" value="PROQ3h1w" id="addblock_input_queryID"/> </td>
</tr>
<tr style="display:none;">
<td colspan="2">
<input type="hidden" name="treePath" value="" id="addblock_input_treePath"/> </td>
</tr>
</table></form>
div with javascript call
<div id="querytree">
<h1>Property Search</h1>
<h2>Select Query Block Type</h2>
<p>Select a section for which to define query criteria.</p>
<div class="queryblocktools"><img style="vertical-align:top;" alt="Load" src="/echemportal/etc/img/load.gif"/> Load Query</div>
<ul class="listexpander">
<li>Physical and chemical properties<ul>
<li>Melting point/freezing point</li>
<li>Boiling point</li>
</ul>
</div>
You are trying to set value on hidden input is which not visible on the page, that's why error has occurred. If you want to set value on hidden field try using execute_script as below :-
treePath_tag = driver.find_element_by_name("treePath")
driver.execute_script('arguments[0].value = arguments[1]', treePath_tag, '/TR.SE00.00/QU.SE.DATA_ENV/QU.SE.ENV_ENVIRONMENT_DATA/QU.SE.EN_MONITORING')
After setting value on hidden field you can use following to submit the form :-
selenium.find_element_by_name("add_form").submit()
Hope it helps..:)

Submit form to email, then redirect to new page (without php)

The client has a section of her site that is not navigable through any other pages. To get to these pages she wants the user to fill out this form. It's a non-for-profit, so she basically just wants to see how many people are getting to these pages that have a product available for free so she can report on that. So there is a page with a form. She wants the user to submit the form and then be re-directed to another page. Normally I would do this really easily with PHP but unfortunately she hosts the site through some local fools and they don't support PHP
So the question is, how do I get this form to submit to her email, then redirect to a different page (videos.html) from the current page with the form (video-form.html)?
I have this form:
<form id="myForm" action="mailto:mail#mail.net" method="post" name="VideoFormAction">
<table cellspacing="1" cellpadding="1" width="46%">
<tr>
<td valign="top" class="shade1"><font color="red"><b>*</b></font> Email Address</td>
<td valign="top"><input type="text" name="Mail" value="" size="30"></td>
</tr>
<tr>
<td valign="top" class="shade2">Name</td>
<td valign="top"><input value="" name="Name" type="text" size="30" maxlength="100"></td>
</tr>
<tr>
<td valign="top" align="center">
<font color="red"><b>*</b></font> = required field
</td>
<td valign="top">
<button class="button">Submit</button>
</td>
</tr>
</table>
</form>
I have tried some javascript:
<script>
document.getElementById("myForm").onsubmit = function() {
setTimeout(function(){
window.location.href = "http://www.funducate.net/videos.html";
}, 1);
};
</script>
Which for whatever reason will not work. I have found multiple suggestions through search to try many different variations of the above, all of which failed. The last ditch effort was even putting a timeout into it as you see above. I imagine it doesn't work because the submit button performs the action="" and then doesn't continue.
Are there any other alternatives? Remember, I can't use PHP (i know it's ridiculous but it's what I got)
You could read the form values via either jQuery or javascript, save them to variables, construct a message body and email the form contents.
See below for more information:
How to send an email from JavaScript
More information on Mandrill
After sending the email, redirect the page as you have done (correctly) in your code -- but without the setTimeout.

Is Wordpress hijacking my Ajax form post?

I'm new to Wordpress and new to JQuery, so let me start off explaining what I am trying to do.
I have an admin page, inside this page I'm giving the user the ability to upload an image. I want this done using Ajax (independent from the general form update).
Here is the code I have so far:
At top of page - script includes:
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://malsup.github.com/jquery.form.js">
I can confirm these scripts are "pingable" and work.
Now the HTML code :
<table width="100%">
<tr>
<td width="100" style="padding:10px" valign="top">Email Image (180x180):</td>
<td style="padding:10px"><img id="previewEmailImage" width=180 height=180>
</td>
</tr>
<tr>
<td></td>
<td>
<div id='emailpreviewloader'>
</div>
</td>
</tr>
<tr>
<td></td>
<td>
<form id="imageform" method="post" enctype="multipart/form-data" action="/ajaximage.php">
<input type="file" name="photoimg" id="photoimg" />
</form>
</td>
</tr>
</table>
The key things in the HTML is a) a form and b) The div emailpreviewloader.
Now just after the html table, inline I have the following js:
<script type="text/javascript">
$(document).ready(function()
{
$('#photoimg').live('change', function()
{
$("#emailpreviewloader").html('');
$("#emailpreviewloader").html('<img width="180" src="/loader.gif" alt="Uploading...."/>');
$("#imageform").ajaxForm(function(result)
{
alert("Thank you for your comment!");
});
});
});
</script>
for testing purposes ajaximage.php just contains 1 line: Echo "It worked";
So assuming I've done my job right, and the html + js above is correct, it would seem Wordpress might be hijacking the Ajax somehow and preventing it from working as expected. Is this possible?
All I want to do is have a regular Ajax post, how is this possible?
EDIT:
What is working:
The change event for the file upload control is firing. I've confirmed this with an alert, and the loader.gif is visible. But it would seem the form isn't firing, or not firing correctly. The inner alert, never fires.
If you don't want to use wordpress's functions for ajax calls, try sending the form to action="<?php bloginfo('template_url');?>/ajaximage.php" and make sure the file is in the root of your wordpress instalation.

Submitting form via jQuery (Javascript) failing

What am I missing here? If I try to submit the form via javascript it doesn't work.
Error (submitting with a regular JS reference and jQuery reference returns the same error)
SCRIPT3: Member not found.
Code:
Refresh customer data
<script type="text/javascript">
function refresh_customer_data()
{
$("#post-form").attr("action", "../scripts/refresh-customer-data.asp");
$("#post-form").submit();
}
</script>
<form method="post" action="" id="post-form">
<input type="hidden" name="fromsubmit" value="true" />
<table class="form" style="height:50px;">
<tfoot>
<tr>
<td><span class="required">*</span> Accessible by administrators only</td>
<td><input type="submit" name="submit" value="" style="display:none;" /></td>
</tr>
</tfoot>
</table>
</form>
Thanks!
Why not use jQuery post to send your data to server page like this
Refresh customer data
Javascript:
$(function(){
$("#aRefresh").click(function(e){
e.preventDefault();
$.post("../scripts/refresh-customer-data.asp", $("#post-form").serialize(),function(data){
//do whatever with the response from server page
})
});
});
Instead of inline calling the function, why not use jQuery to do it for you:
http://jsfiddle.net/8XdwS/
I know this is an old thread but for everybody's information:
I have come across this issue as well, and the problem was having the submit button named submit.
Renaming the submit button ie. to submit2 solved the issue.

upload a file via a form using ASP

I have a simple html form in a .asp page. I would like add a field to let users upload files via the form on my server/ftp on the fly. Any suggestions on how I can do this please?
this is the code I am using for the HTML
<form name="formUpload" id="formUpload" method="post" enctype="multipart/form-data" action="">
<table valign="top" align="left" bgcolor="PaleGoldenRod" width="300px" border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="PaleGoldenRod" valign="top">
<td width="300px">
<input type="file" size="50" name="file1">
<input type="submit" name="submit" value="Upload File">
</td>
</tr></table></form>
I have no idea how to do this because I never had done something like this.
You could try the following jQuery plugin to handle 'on the fly' uploads:
jQuery File Upload
But like Symeon said, you will need an ASP Classic component that will handle the file uploads on the server. I used the FreeASPUpload version a couple of times, works like a breeze.
In ASP you have to write your own upload handler to take the http stream and write it to disk - there is plenty of example code on the web. I have some, but it is a bit big to post here.
Look at this or this
HTH

Categories

Resources