I am submitting the form using jquery. Now i need to send form information into external server. The below is the part of my code that submit the form to another server. It works in all browsers except IE which gives me access denied error.
$.ajax({
url:"https://www.thewiseagent.com:443/secure/webcontactAllFields.asp",
type:'POST',
data:"ID=" + $ID + "&Source=" + $Source + "¬ifyCc=" + $notifyCc + "¬ifyBcc=" + $notifyBcc + "&noMail=" + $noMail + "&CFirst=" + $first + "&CLast=" + $last + "&Phone=" + $Phone + "&Fax=" + $Fax + "&CEmail=" + $CEmail + "&Message=" + $message,
success: function() {
}
});
Any help?
You can not make an AJAX call to a different domain. See my answer here: jQuery ajax GET returns 405 Method Not Allowed
That being said if it truely works in other browsers then I'm assuming you're posting to the same domain. Then you have to look at the returned content. There should be no reason you'd get a 405 from IE but not from FF.
I suspect though that this doesn't work with other browsers either, because of the javascript security restrictions.
Related
I'm learning JavaScript but I want the following thing in my little (self-started) project as soon as possible.
Suppose the page of my website is www.mywebsite.com/myPage.html
Here is a scenario that 10 users are viewing myPage.html from my website. As I make any change to myPage.html from server (being admin), I want all viewers of myPage.html to see refreshed page with new changes taken effect just after I make any change in myPage.html. It should be very fast.
For this I think I'll have to create a button which will refresh the page myPage.html. As I'll make changes to myPage.html, I'll press that button and that button will reload every viewer's browser's page (myPage.html). And they will see the result of modified myPage.html in their browsers.
Kindly explain your answer properly, since I'm a beginner. Which Languages are needed for this?
i think the best option here would be some kind of push implementation / web sockets ... here are a few links to get you started in the right direction ...
Websockets : Using modern HTML5 technology for true server push
Push Notifications to the Browser With Server Sent Events
In the case of socket.io in client side(browser) subscribe every client with a particular channel and make the page reload with javascript when request from server via that channel is recieved. And in server you can broadcast message to that particular channel whenever you want to reload the page.
you can create an AJAX function that is executing in intervals(like every 10 seconds) and this function will connect to server to ask for any update from mysql, so if there's any updates! you notify the user.
so you should create a table in DB to be updated with page update info when you update a page.
AJAX(asynchronous javascript and xml ) is a technology connect to your server without having to use Forms to post, and you can refresh part of your page automatically.
now here is an example:
I wanted to create an online chat, so here is the code:
this code use ajax to post to ChatNotifyController.php to see if theres anyone online,if there's any it will notify the user.
//notify user if someone has or had send a message
setInterval(function(){
xmlhttp.open("POST" , "../controller/ChatNotifyController.php" , true);
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4)
{
if(xmlhttp.status == 200)
{
if((xmlhttp.response).length > 4)
{
var friendName = (xmlhttp.response).replace(/^\s*$[\n\r]{1,}/gm, '');
var responseArea = document.getElementById( friendName + 'ChatArea');
var x = friendName ;
if(x.indexOf('.') > 0)
{
x = x.replace('.', '\\.');
}
var link = $('#' + x);
var input = $('#' + x + 'ChatInput');
var e = jQuery.Event("keydown");
e.which = 13;
if(link.length > 0)
{
link.click();
input.trigger(e);
}
else
{
var html = "<li><a class=\"onlineUserLink\" id=\"" + friendName + "\" onclick=\"chat(" + "'" + friendName + "'" + ")\" >" + friendName + "</a></li>";
html += "<div class=\"chatDialog\" title=\"'" + friendName + "\"' id=\"'" + friendName + 'ChatDialog' + "'\">";
html += "<div class=\"chatArea\"" + " id=\"'" + friendName + "ChatArea" + "'\">" + "</div>";
html += "<input class=\"chatInput\"" + " id=\"'" + friendName + 'ChatInput' + "'\" size=\"21\" onkeydown=\"chatController(event , '" + friendName + "' , '" + window.user + "')>" + "</div>";
window.onlineArea.innerHTML += html;
var THIS = $('#' + x + 'ChatDialog');
$(function() {
THIS.dialog({
stack: false
});
});
link.click();
input.trigger(e);
}
}
}
else
{
//alert("Error during AJAX call. Please try again #003");
}
}
};
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send("user=" + window.user);
} ,5000);
I'm having a problem with a TinyMCE plugin using long GET parameters. On my development server, the plugin works just fine. However, on the production server, the parameter is ignored.
The plugin is SMImage, it uses parameters like this one:
40a6ff4a9832c3e3f8e2fed4d50dc8c6cc42409476b487da936f60cf315f57ccc39c7629d4146097ade572cdf409083257eb2d6edbff7b46556efafd07d4802521d17e14d1021baeac712f8ee83be1f768f14f849e58edb37c8fcd9a8e61e5235a1bb885b0dd1c5b85a2642f22fba99d304a6f988795e1c2b088b8f80e7acc69bc0cea7f763320a6611bd24bc924e0e1bda887990f560cbbd9e1608545fd69859a1808286a263d4754b8b1f6a713c9bdaaa015649b92db2701b005bd91e6827ff4bde6b48bcb0e5ca509f568684c51a803dbc7f896cdfdbcd0cfafc202e20d68f45cdfe86b033f36ff05a0f52cc6381231682d20d3038fc4fe7aba0916c614e89ff2b64c6b6bae0b548f
Which is kinda long, but shouldn't be much of a problem (except on IE of course).
Under the production server, $_GET['get'] is not even defined, since it's ignored by PHP.
Is there a server setting that can be changed perhaps? Under PHP, what defines the maximum length?
I could use POST instead, but I'm not too sure how I could change this part of the plugin:
var get = 'id=1' + '&dir_root=' + ed.getParam('plugin_smimage_directory', '') + '&server=' + ed.getParam('plugin_smimage_server', '') + '&thumbnail_size=' + ed.getParam('plugin_smimage_thumbnail_size', '') + '&show_thumbnail=' + ed.getParam('plugin_smimage_show_thumbnail', '') + '&jpg_quality=' + ed.getParam('plugin_smimage_jpg_quality', '') + '&orderby=' + ed.getParam('plugin_smimage_orderby', '') + '&show_upload=' + ed.getParam('plugin_smimage_show_upload', '') + '&show_image_menu=' + ed.getParam('plugin_smimage_show_image_menu', '') + '&show_folder_menu=' + ed.getParam('plugin_smimage_show_folder_menu', '') + '&show_newfolder=' + ed.getParam('plugin_smimage_show_newfolder', '') + '&thumbnails_perpage=' + ed.getParam('plugin_smimage_thumbnails_perpage', '') + '&upload_filesize=' + ed.getParam('plugin_smimage_upload_filesize', '') + '&check_session_variable=' + ed.getParam('plugin_smimage_check_session_variable', '') + '&document_root=' + ed.getParam('plugin_smimage_document_root', '');
ed.windowManager.open({
file: url + '/index.php?get=' + SMImage_BinToHex(SMImage_RC4(get)),
width: ed.getParam('plugin_smimage_width', '800'),
height: ed.getParam('plugin_smimage_height', '500'),
inline: 1
},
{
plugin_url: url
})
Not sure if this is good idea, but you could try using cookie as workaround for passing that kind of parameters. In JS, before calling this window open, do smth like
document.cookie = 'SMImage_param=' + SMImage_BinToHex(SMImage_RC4(get))
and then call index.php without parameters. On server-side use
$_COOKIE['SMImage_param']
for getting this parameter value.
Of course, it will work only if PHP you are calling is on the same domain (but I'm almost sure that for your TinyMCE plugin it's there).
Okay, I created a flash register for my website, it's very simple.
This is the main code:
var LoadRegisterVaribles:LoadVars = new LoadVars();
LoadRegisterVaribles.onData = function(Varibles:String) {
error_mc.error_txt.text = Varibles;
};
LoadRegisterVaribles.load(
"http://216.120.248.106/register/register.php?username=" + Username_mc.name_txt.text +
"&password=" + Password_mc.pass_txt.text +
"&email=" + Email_mc.email_txt.text +
"&color=" + _root.color_txt.text + "");
What it does is load the register.php and adds the extensions in a fancy flash GUI.
Works perfectly; But when I upload it to my website http://216.120.248.106/, or www.spuffle.in, it does not connect. I have crossdomains.xml, that allow (*) all in every directory, but does not work, the cross domains worked for other things I have on my site, so they are configured properly. I also have Security.AllowDomains
Security.allowDomain('spuffle.in');
Security.allowDomain('spuffle.me');
Security.allowDomain('spuffle.us');
Security.allowDomain('play.spuffle.me');
Security.allowDomain('play.spuffle.in');
Security.allowDomain('play.spuffle.us');
Security.allowDomain('spuffle.me/play/');
Security.allowDomain('spuffle.in/play/');
Security.allowDomain('spuffle.us/play/');
Security.allowDomain('www.spuffle.in');
Security.allowDomain('www.spuffle.me');
Security.allowDomain('www.spuffle.us');
Security.allowDomain('www.spuffle.me/play/');
Security.allowDomain('www.spuffle.in/play/');
Security.allowDomain('www.spuffle.us/play/');
Security.allowDomain('media.spuffle.in/media/');
Security.allowDomain('media.spuffle.me/media/');
Security.allowDomain('media.spuffle.us/media/');
Security.allowDomain('www.spuffle.in/media/');
Security.allowDomain('www.spuffle.me/media/');
Security.allowDomain('www.spuffle.us/media/');
Security.allowDomain('*.spuffle.in/*/');
Security.allowDomain('*.spuffle.me/*/');
Security.allowDomain('*.spuffle.us/*/');
Security.allowDomain('216.120.248.106');
Security.allowDomain('216.120.248.106/register/');
Security.allowDomain('216.120.248.106/register/Pages/');
Security.allowDomain('216.120.248.106/register/register.php');
What can I do??
When you embed the SWF on the HTML page, try setting the allownetworking parameter: http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS1EFE2EDA-026D-4d14-864E-79DFD56F87C6.html
I have been working on a website that uses a combination of PHP, jQuery, MySQL and XHTML in order to register students for a piano recital. This has no official purpose other than a learning exercise for me in getting all of these to work together. However, I have had a lot of problems getting the PHP to talk with the database and I'm not sure what my problem is. But before that can be tackled there is a really annoying issue that I've run across. For some reason my jQuery is not building a complete post URL for the PHP.
I am using jQuery version: 1.4.2 from Google. The query string is being built by using:
var ajaxOpts = {
type: "post",
url: "../php/addRecital.php",
data: "&performance=" + $("#performanceType :selected").text() +
"&groupName=" + $("#groupName").val() +
"&student1fName=" + $("#firstName").val() +
"&student1lname=" + $("#lastName").val() +
"&student1id=" + $("#studentID").val() +
"&student2fname=" + $("#Second_Student_firstName").val() +
"&student2lname=" + $("#Second_Student_lastName").val() +
"&student2id=" + $("#Second_Student_studentID").val() +
"&skillSelect=" + $("#skillSelect :selected").text() +
"&instrument1=" + $("#instument1 :selected").text() +
"&otherInstrument1=" + $("#otherInstrument1").val() +
"&instrument2=" + $("#Instument2 :selected").text() +
"&otherInstrument2=" + $("#otherInstrument2").val() +
"&location=" + $("#locationSelect :selected").text() +
"&roomNumber=" + $("#roomNumber").val() +
"&time=" + $("#timeSlotSelect :selected").text()
,
success: function(data) { ...
There is more than the above function, but I didn't think that it would pertain to here. I then call the code using:
$.ajax(ajaxOpts);
However, instead of creating the entire query string I get:
http://sterrcs123.mezoka.com/schoolProject/assign/assign13.html?groupName=&firstName=Samuel&lastName=Terrazas&studentID=23-343-3434&Second_Student_firstName=&Second_Student_lastName=&Second_Student_studentID=&otherInstrument=&Second_Student_Instrument=&roomNumber=2
Which as you can tell is missing a number of keys and their values. I would appreciate any help I can get because this is really driving me insane. Thanks.
It appears that your form is simply submitting itself without using your AJAX operation. Did you attach to the form's submit event and THEN run your ajax call? You will also want to return false from the submit event handler to prevent the default behavior you are seeing above.
Example:
$('#formid').submit(function(){
//your ajax code here.
return false;
});
If you're talking to an ASP.Net web service then you would need data to be a JSON string of your arguments. Otherwise, you can pass your data in by using an object literal (truncated for brevity):
var ajaxOpts = {
type: "post",
url: "../php/addRecital.php",
data: {
performance: $("#performanceType :selected").text(),
groupName: $("#groupName").val(),
student1fName: $("#firstName").val(),
student1lname: $("#lastName").val()
},
success: function(data)
}
As per the missing values, make sure you're capturing the button click / form submit.
$('form').submit(function (e) {
$.ajax(ajaxOpts);
return false;
});
I am posting some form values through ajax to a PHP script. The PHP echoes 1 if it's successful and 2 if not.
The PHP seems to be working ok but I am being redirected to the url in the javascript and shown the number 1 on a blank page instead of it being echoed back to the ajax request.
This is my javascript, can anyone see where I am going wrong?
$(".save").click(function() {
var area = $("input#area").val();
var january = $("input#january").val();
var target = $("input#target").val();
var ach = $("input#achieved").val();
var comments = $("input#comments").val();
var token = "<?php echo $token; ?>";
var dataString = 'area='+ area + '&january=' + january + '&target=' + target + '&achieved=' + ach + '&comments=' + comments + '&ci_token=' + token;
$.ajax({
type: "POST",
url: "review/update-review/<?php echo $yr; ?>",
data: dataString,
success: function(msg) {
if(msg == 1)
{
alert("Your review has been updated.");
}
else
{
alert("There was a problem updating your review. Please try again.");
}
}
});
return false; });
I think the problem may be down to the format of your data parameters. for
type : "POST"
then for
data : "{param1: 'param1', param2: 'param2'}"
do you have a tool like fiddler to view the communications between your browser and server. if not i would recommend downloading fiddler (it's free). it will give you a lot of insight as to what is actually happening behind the scenes and can give invaluable information about what might have gone wrong with an ajax style post.
The code looks pretty much fine to me, including the syntax. Still some possibilities arise, which are:-
The URL for executing the PHP code, which you are using in the example ("review/update-review/<?php echo $yr; ?>"), may be incorrectly given with reference to your current page.
The variables which you are using it here to capture the values of the INPUT elements, may be producing some extra special characters (like "&") which may lead to erroneous processing, resulting in the JavaScript problem.
Hope it helps.
For starters if(msg == 1) will not be == 1 because what your fetching is a string so it would b if(msg == '1').
Where you have
var dataString = 'area='+ area + '&january=' + january + '&target=' + target + '&achieved=' + ach + '&comments=' + comments + '&ci_token=' + token;
Change that to an object like so:
var dataObject = {
area : area,
january : january,
target : target,
achieved : ach,
comments : comments,
ci_token : token
}
and then change it in the ajax request to dataObject
Debug
Firefox: firbug.
if your using chrome hit Ctrl+Shift+J to open the javascript console and debug. look out for all the heaDers and data your sending and you can use console.log(varaible) to track the values of a variable.