JQuery.post Failed to execute 'postMessage' - javascript

I have a simple $.post() that I want to execute
function(formData) {
var path = reg ? "login" : "regester";
formData.bundle_id = window.bundleId;
app.error = false;
app.unknown = false;
$.post(("/kanban/"+path+"/submit"),{"form":formData},function(data){
if(data.success){
window.location.href=data.redir;
}
else if(data.user) {
window.location.href="/kanban";
}
else {
app.error = true;
}
})
.fail(function(jqXHR, textStatus, errorThrown) {
app.unkown = true;
});
}
The app is defined by
const app = new Vue({...});
Currently, when the function is called I get the error
jquery.js:8463 Uncaught TypeError: Failed to execute 'postMessage' on 'Window': 2 arguments required, but only 0 present.
at add (jquery.js:8463)
at buildParams (jquery.js:8450)
at buildParams (jquery.js:8444)
at Function.jQuery.param (jquery.js:8483)
at Function.ajax (jquery.js:9073)
at Function.jQuery.(/kanban/anonymous function) [as post] (https://127.0.0.1/kanban/js/jquery.js:9355:17)
at submitForm (register?bundle_id=-1:84)
at <anonymous>:1:1
I'm not sure what could be causing this. It may be a simple syntax error but I can't find one.
I call my js method from here
<form action="javascript:submitForm(this)">
......
</form>
I'm running on Google Chrome Version 69.0.3497.81 With jquery-3.3.1
I also have vue.js and alertify.js loaded on this page.
Is there a syntax problem I'm missing? Or is there a possible overlap.

You are trying to pass a form element to $.post as data and that can't be serialized.
Try changing to
var data = $(formData).serialize()
$.post("/kanban/"+path+"/submit", data, function(data){..
Now server will receive the data exactly the same way it would if the form was submitted using default browser process
Would also consider changing name of formData to form to minimize confusion

Related

how to redirect page in html?

i am writing page in html and i have server/database on parse.com .
parse provides login function which checks if username and password is matched in a database. i have done this part but when i get success it is not redirecting into other page. here is the code :
$("#login").click(function(event)
var name = $(#name).val();
var pass = $(#password).val();
Parse.User.logIn(name, pass, {
debugger
success: function(user){
window.location="login/login.html";
console.log("everything OK")
}, error: function(user, error){
console.log("Log in Error:"+error.message);
}
});
});
i have searched for redirecting the page and found out the window.location but it is not working. what is the error please help me.
By the way i got error message at this line var name = $(#name).val(); with error message :
Uncaught SyntaxError: Unexpected token ILLEGAL
You have a couple of problems in your code which is stopping it from running. Unexpected token ILLEGAL is the browser's way of telling you that it doesn't understand your code.
1) You're missing the opening brace in the first function
2) In the jQuery selectors, you need to wrap the selectors in quotes - $("#name").val() and $("#password").val()
3) Your debuger statement is misplaced. You've put it inside an object definition, and it doesn't make sense there. Move it to inside the function below. (It's also spelt debugger with 2 g's :) )
$("#login").click(function(event) { // 1) include brace
var name = $("#name").val(); // 2) include quotes
var pass = $("#password").val();
Parse.User.logIn(name, pass, {
success: function(user){
debugger; // 3) move debugger statement to a valid location
window.location="login/login.html";
console.log("everything OK")
},
error: function(user, error) {
console.log("Log in Error:"+error.message);
}
});
});
You need to pass both of your selectors in quotes
var name = $("#name").val();
var pass = $("#password").val();
That will stop the error and should work.
This is riddled with errors and missing semicolons and parantheses. Try this
$("#login").click(function(event) {
var name = $("#name").val();
var pass = $("#password").val();
Parse.User.logIn(name, pass, debuger);
success: function(user){
window.location="login/login.html";
console.log("everything OK")
}, error: function(user, error){
console.log("Log in Error:"+error.message);
}
});
});

Parse.com Uncaught TypeError: Cannot read property 'className' of undefined JavaScript

After having manually created a record within an object named "Cards" in parse.com with an objectId of 9e9JAIYSFa, I am attempting to retrieve attributes (attack and defense) of this record by closely following the documentation.
alert("1");
var Cards = Parse.Object.extend("Cards");
alert("2");
var cards = new Cards();
alert("3");
var query = new Parse.Query(cards);
alert("4");
query.get("9e9JAIYSFa", {
success: function (cards) {
alert("5");
},
error: function (object, error) {
alert("6")
}
});
alert("7")
var attack = cards.get("attack");
var defense = cards.get("defense");
alert("8");
alert(attack);
alert(defense);
alert("9");
This returns the error in chrome:
Uncaught TypeError: Cannot read property 'className' of undefined
which is pointing to line 3 of the parse-1.3.2.min.js file.
A point worth noting is that only alerts 1, 2 and 3 are displayed.
After looking at these questions:
Parse - Uncaught TypeError: Cannot read property 'get' of undefined
Uncaught TypeError: Cannot read property 'get' of undefined - How do I solve this?
how can i update current object in parse.com with javascript?
I tried accessing the objectId manually using this code:
query.equalTo("objectId", "9e9JAIYSFa");
query.find({
success: function (cards) {
alert("Working");
},
error: function (object, error) {
alert("Not working");
}
});
But this also results in the same error.
Any ideas?
The parameters of Parse.Query should be class rather class instance. -- ref. Parse.Query
It should fix the problem by replacing cards from var query = new Parse.Query(cards); to Cards as var query = new Parse.Query(Cards);.

jQuery Uncaught TypeError: Cannot read property 'text' of null

Problem: I am loading a modal form from an ajax call. Within the modal, I have a span element holding an email address. I am needing to capture the value of the span element in javascript. Currently, I have a button click that calls a function to obtain the text.
Code to read text:
function AccountHistoryRedeemSendEmail(emailType)
{
clearNotifications();
console.log('Hit AccountHistoryRedeemSendEmail');
var url = "../../utility/account/ajaxAccountHistoryRedeemSendEmail.aspx";
var params = "eType" + emailType;
//console.log($('#lblHRedeemEmailAddress'));
console.log('Output text: ' + $('#lblHRedeemEmailAddress').text());
params += "&HRedeemEmailAddress=" + $("#lblHRedeemEmailAddress").text();
params += "&timestamp=" + new Date();
// new Ajax.Request(
// url,
// {
// method: "get",
// parameters: params,
// onSuccess: parseAjaxResponseAccountHistoryRedeemSendEmail
// }
// );
}
The error being returned is: "Uncaught TypeError: Cannot read property 'text' of null "
I understand the error is telling me $('#lblHRedeemEmailAddress') is returning a null. Naturally, I have verified my element name to be correct. I have also inspected the element in chrome and verified it is present in the document. Here is html in the document:
<span id="lblHRedeemEmailAddress">name#domain.com</span>
< img src="sendemail.jpg" id="SendEmail" alt="Email Certificate" onclick="AccountHistoryRedeemSendEmail('lblEmail');">
So, the question: Why is my lblHRedeemEmailAddress element null when I try to access it from the function? And, how do I fix this?
If lblHRedeemEmailAddress didn't exist, jQuery would return an empty result set, upon which you would still be able to call text. $ is probably referring to some other library, such as prototype.
Read up on noConflict or create a closure where $ is set to jQuery:
(function($) {
// for anything in here, $ will be jQuery
})(jQuery);

what does Uncaught SyntaxError: Unexpected token < mean?

For this line of code :
var result = eval('('+result+')');
In this context:
function saveUser(){
alert(url);
$('#fm').form('submit',{
url: url,
onSubmit: function(){
return $(this).form('validate');
},
success: function(result){
var result = eval('('+result+')');
if (result.errorMsg){
$.messager.show({
title: 'Error',
msg: result.errorMsg
});
} else {
$('#dlg').dialog('close'); // close the dialog
$('#dg').datagrid('reload'); // reload the user data
}
}
});
}
How do i fix the error?
what does Uncaught SyntaxError ... mean?
It means that eval cannot parse the input (as JavaScript) because it contains a < where there shouldn't be one. FWIW if the response is HTML, JSON.parse wouldn't help either.
How do i fix the error?
You either have to treat the response how it is expected to be treated, e.g. don't pass it through eval if it's HTML.
Or you fix the server side and return the repsonse that the client side expects, e.g. JSON.

Jq grid - TypeError: e is undefined for custom server response

i code a custom function to display the server response after submit the edit form , i am getting TypeError: e is undefined on the file jQuery.jqgrid.min.js line number 339
...call(l,f,D):g+" Status: '"+f.statusText+"'. Error code:
"+f.status}else{e=a(l).t...
i used function as per this stack question
afterSubmit: function (response, postdata) {
var res = $.parseJSON(response.statusText);
if (res && res.insertStatus) {
alert(res.insertStatus);
}
return true;
}
i am geting server response as a json as follow
{"statusText":"Data Updated Sucessfully"}

Categories

Resources