Posts Tagged ‘ajax’
Monday, August 23rd, 2010
hi…i’ve been a prototype user for a few years, and now for several reasons, i’m moving to jquery.. but still have yet familiarize myself with jquery’s syntax.. my question is
how do I convert this prototype code to jquery correctly?
new Ajax.Updater('displayArea', 'shoutbox.php', { method:'post',
parameters: {action: 'display', some_data: some_data}
});
and here’s what i did:
$.post("shoutbox.php", {action: "display", some_data: some_data}, function(data){$("#displayArea").text(data);},"html");
i got the exact return result from jquery and prototype, but the problem is, when jquery updates the “displayArea”, it’s not quite what I expected. the returned data has some html codes in it, and instead of displaying a new line for the html tag ‘br’, jquery just display the ‘br’ in plain text. what i means is it’s displaying html codes, and that’s not what I want. hope you all get what i meant….
thanks
Tags: ajax, html codes, html tag, jquery, parameters, prototype code, return result, shoutbox php, syntax
Posted in dotnet, vb, vb.net | No Comments »
Monday, August 23rd, 2010
I am having problem uplaoding file,
here are my codes:
Any help? Thanks!
test.html
function insertPhoto()
{
var description = document.getElementById('description').value;
var image = document.getElementById('photo').value;
var url = "ajax_insert.php?action=add&image="+image+"&description="+description;
var ajaxRequest = ajax_obj();
ajaxRequest.onreadystatechange = function() {
if(ajaxRequest.readyState == 4){
document.getElementById("msgbox").innerHTML=ajaxRequest.responseText;
}
}
ajaxRequest.open("GET", url, true);
ajaxRequest.send(null);
return false;
}
<div align="center">
<div class="top" >
<div>
Decription <input name="description" type="text" id="description" value="" maxlength="20" />
</div>
<div style="margin-top:5px" >
Image
<input name="photo" type="file" id="photo" value="" maxlength="20" />
</div>
<div class="buttondiv">
<input name="button" type="button" value="Upload" onclick="return insertPhoto()" style="margin-left:-10px; height:23px" />
<span id="msgbox" style="display:none"></span>
</div>
</div>
</div>
ajax_insert.php
<?php
mysql_connect('localhost','root','');
mysql_select_db('priceless');
define('DIR_IMAGE','images/');
$image = $_GET['image'];
$description = $_GET['description'];
$dbtable = 'photos';
$action = $_GET['action'];
if($action == 'add'){
$photo = '';
if ($_FILES[$image]['name']) {
$aray = explode(".",$_FILES[$image]['name']);
$ext = $aray[count($aray)-1];
$photo = date('Ymdhis').'.'.$ext;
move_uploaded_file($_FILES[$image]['tmp_name'],DIR_IMAGE.$photo);
}
$data = array(
'image'=> $photo,
'description'=> $description
);
$values = array();
foreach($data as $show){
$values[] = $show;
}
$query = "INSERT INTO ".$dbtable." (`".implode("`,`",array_keys($data))."`) values ('".implode("','",array_values($values))."')";
if ($result= mysql_query($query) or die(mysql_error())) {
echo "You have Sucessfully Upload Photo!";
}
}
?>
Tags: ajax, description document, image document, photo
Posted in dotnet, vb, vb.net | No Comments »
Monday, August 23rd, 2010
I’m building a site that requires multiple forms for the same model in varying numbers throughout a single page. These forms belong to an object with an id. Currently, since I can’t figure out how to change the form ids, I’m stuck with a hole bunch of duplicate ids.
I’m looking for a way to append the object id to the form id so they’re not invalid. I’m prefer to write my own javascript so I will not use the ajax helper.
<?php
/**
* This is a simplified example of what I am trying to do.
*/
?>
<div id="objects">
<?php foreach($objects as $object): ?>
<div class="object">
<?php echo "this is object {$object['Object']['id']}"?>
<?php
//The following element would show a number of comments the object owns
echo $this->element('object_comments_loop', array('comments' => $object['Object']['Comments']);
?>
<div class="comment">
<?php
//each object has a form.
//TODO: this is where the id issue comes into play.
echo $form->create('Comment', array('url' => array('controller' => 'comments', 'action' => 'createComment'));
echo $form->hidden('object_id', array('value' => $object['Object']['id']));
echo $form->input('comment_body', array('label' => __('comment', true), 'type' => 'text'));
echo $form->end(__('comment_submit', true));
?>
</div>
</div>
<?php endforeach; ?>
</div>
Tags: ajax, hole bunch, object id
Posted in dotnet, vb, vb.net | No Comments »
Sunday, August 22nd, 2010
I am having a problem checking if a file exists using $.ajax(). I am looping through a json file with $.each and I want to see if the specified staff member has an image, and if not use the no_photo.jpg image. I keep getting the no_photo.jpg image even though there is the staff member’s image in the directory.
Here is the entire $.getJSON() call.
$.getJSON('staff.json', function(data) {
var last_check;
var image_url = "no_photo";
$.each(data.employees, function(i,employee){
if ((i+1)%4==0) {last_check = " last";} else {last_check = "";}
$.ajax({
url:'/images/staff/' + employee.first_name.toLowerCase() + employee.last_name.toLowerCase() + '.jpg',
type:'HEAD',
error:
function(){
image_url = "no_photo";
},
success:
function(){
image_url = employee.first_name.toLowerCase() + employee.last_name.toLowerCase();
}
});
$("div.staff-members").append('<a href="#" title="' + employee.first_name + ' ' + employee.last_name + ', ' + employee.title + '" rel="' + employee.location + '" class="' + employee.category + last_check + '"><img src="/images/staff/' + image_url + '.jpg"><span class="' + employee.category + '"></span></a>');
});
});
Tags: ajax, error function, images, photo, staff employee, staff member, staff members
Posted in dotnet, vb, vb.net | No Comments »
Sunday, August 22nd, 2010
I am using slideUp and slideDown in the beforeSend ajax event which works fine is firefox, but in other browsers, the ajax postback seems to complete before the slideUpDown has completed so my success function is executed first, then the slideUp/Down.
How can I change it to either (1) not send the ajax until the slideUp/Down have completed or (2) not process the result in the success function until the slideUp/Down have completed?
I tried creating a isAnimationFinished variable which is set when the slideDown has finished and in the success, I have an empty while loop that waits for this variable, but I get an error about a script running slowly if I try this.
Tags: ajax, animations, callback, postback
Posted in dotnet, vb, vb.net | No Comments »
Sunday, August 22nd, 2010
I am building an message board application using Javascript and PHP. When I try to load a php script via Ajax, I get a 500 internal server error. If I load basic text instead of php, the Ajax call works fine and the text is displayed.
Anyone know why the server would have trouble with this?
Here’s my php file:
<?php
//Get input from my form
$from = $_POST["guestbook_from"];
$msg = $_POST["guestbook_msg"];
$today = getdate(date("U"));
recordMessage($from,$msg); //external php function, creates database record
//Print some html
echo("<p>");
echo($msg);
echo("</p>");
echo("<h4>");
echo($from);
echo("<br />");
echo("<small>");
echo("posted on ");
echo($today[month]);
echo(" ");
echo($today[mday]);
echo(", ");
echo($today[year]);
echo("</small>");
echo("</h4>");
?>
Tags: 500 internal server error, ajax, internal server error, message board application, php file, php script
Posted in dotnet, vb, vb.net | No Comments »
Sunday, August 22nd, 2010
I’m trying to watch for an element to load on the page from an ajax call. I don’t have access to the jquery that’s making the ajax call. So, when some new html is loaded onto the page, I’d like to apply some changes to it.
I’m currently trying to use the .load() function:
$( '.autosuggest_keyword' ).load(
function()
{
$( this ).val( 'load test' );
}
);
Which isn’t doing anything. I even tried making that a live binding, which doesn’t really make sense, but I thought I’d give it a try.
The selector is correct.
Any ideas?
Tags: ajax, element, jquery, load test
Posted in dotnet, vb, vb.net | No Comments »
Sunday, August 22nd, 2010
Wikipedia provides information about one of the most common scenarios for exploiting a reflected cross site scripting attack – using some degree of social engineering to induce unsuspecting users to click a malicious link:
- Alice often visits a particular website, which is hosted by Bob. Bob’s
website allows Alice to log in with a
username/password pair and stores
sensitive data, such as billing
information.
- Mallory observes that Bob’s website contains a reflected XSS
vulnerability.
- Mallory crafts a URL to exploit the vulnerability, and sends Alice an
email, enticing her to click on a link
for the URL under false pretenses.
This URL will point to Bob’s website,
but will contain Mallory’s malicious
code, which the website will reflect.
- Alice visits the URL provided by Mallory while logged into Bob’s
website.
- The malicious script embedded in the URL executes in Alice’s browser,
as if it came directly from Bob’s
server (this is the actual XSS
vulnerability). The script can be used
to send Alice’s session cookie to
Mallory. Mallory can then use the
session cookie to steal sensitive
information available to Alice
(authentication credentials, billing
info, etc.) without Alice’s knowledge.
Now, this is usually tends to be very good example when the website happens to be a page-driven application – the vulnerability is exploited by getting the user to submit a malicious payload to the application (more importantly, by issuing a GET request when logged in) which is reflected back in the response.
Are there any more interesting attack vectors, especially ones to consider when the application utilizes a lot of AJAX with most of the requests being made over HTTP POST?
EDIT
In case I wasn’t clear, I’d like to know the various types of attacks vectors applicable to reflected XSS attacks, especially when the client-side tier of the application is implemented differently. Page-based applications would have an attack vector involving HTTP GET requests issued from a user, but it would be interesting to know how this plays out for thick client applications especially the ones using XMLHttpRequest objects that issue HTTP POST requests. Different mechanisms used in client-side rendering will obviously warrant study of different attack vectors. In some cases, there might not be any applicable attack vectors; the question is expressed to elicit such a response.
Tags: ajax, alice visits, authentication credentials, bob bob, cross site scripting, driven application, email, false pretenses, malicious code, malicious payload, malicious script, mallory, sensitive data, session cookie, social engineering, unsuspecting users, vectors, vulnerability, wikipedia, xss
Posted in dotnet, vb, vb.net | No Comments »
Sunday, August 22nd, 2010
This might be a stupid question, as I am a complete beginner in the world of AJAX/Javascript. However, I am trying to build a website using Ajax combined with PHP/MySQL. The issue I have at hand is that the PHP variables and functions that I have included in the header.php is no longer valid when use Ajax to open a new page (without reloading). Probably a confusing explanation, but as I said; I have no experience in this part of web development, and I’m looking to learn more.
I have a header file which includes various other PHP-files with some classes and functions. This is also where I am connecting to the MySQL database. Following this I have a main menu, where the links are calling a Javascript, in order to show a new page without the reloading. These new pages are dependant on a MySQL-connection, but it seems that they cannot use the existing connection established in the header. I have also tried to simply define the variable"$foot = "Hello"; in the header, but this one also seem to "disappear" when the other pages are loading.
How can I solve this? Any advice is much appreciated!
Tags: ajax, header php, mysql connection, mysql database, php files, php mysql, php variables, reloading, stupid question
Posted in dotnet, vb, vb.net | No Comments »
Sunday, August 22nd, 2010
Hi,
I’m trying to catch Ajax timeout error with jQuery 1.4.2, but none of tutorial I found work. In Firebug, when timeout error fires. I see uncaught exception: [object Object]. Please help me handle Ajax timeout. Here’s my JS code:
$.ajax({
type:"POST",
url:"/data/add/",
data:
{
"date":$("input#date").val();
},
dataType:"json",
timeout:2000,
success: function(response) {
},
error: function () {
alert('Server error');
}
});
Tags: ajax, alert server, error function, exception object, firebug, fires, js, json, object object, response error, server error, timeout error, url data
Posted in dotnet, vb, vb.net | No Comments »