Exception: DateTime::__construct(): Failed to parse time string (17/06/2014) at position 0 (1): Unexpected character + - symfony-2.5

Plz take my issue
-
An exception has been thrown during the rendering of a template
("DateTime::__construct(): Failed to parse time string (17/06/2014) at
position 0 (1): Unexpected character") in
ComAkSolutionsSmsUserBundle:Admin\AcademicYear:manageAcademicYear.html.twig
at line 16.
<script type="text/javascript">
$(function () {
$('#datetimepicker_1').datetimepicker({
viewMode: 'years',
format: 'DD/MM/YYYY'
});
$('#datetimepicker_2').datetimepicker({
viewMode: 'years',
format: 'DD/MM/YYYY'
});
});
</script>

Lookup http://php.net/manual/en/datetime.construct.php - your error message is a PHP error message, your code snippet is from JavaScript. You must pass the time string with the correct format to the php-function too.

Related

Getting a text respons using Fetch API and a PHP file

I am hitting a php file and the response returns a string. I can't find the documentation on how to deal with this.
From the google developer doc google developer doc, my fetch is simple
fetch('upvotes.php')
.then(
function(response) {
if (response.status !== 200) {
console.log('Looks like there was a problem. Status Code: ' +
response.status);
return;
}
// Examine the text in the response
response.json().then(function(data) {
console.log(data);
});
}
)
.catch(function(err) {
console.log('Fetch Error :-S', err);
});
And PHP
<?php
function test(){
return "This is a test";
}
echo test();
?>
This fails on the response.json() assumedly because I am returning just a string. If I log out just the response (attached screen shot) I get something I have no idea how to work with, and I cannot convert it. Where is my return value from the PHP here?
response.json causes the dreaded Uncaught (in promise) SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
How can the value from the PHP?
Your PHP isn't returning JSON, it's just returning a string so use .text() instead.

Integration between Axios and RequireJS fail

I have a error in integration between RequireJS and Axios:
<HEAD>
<script src="3party/require.js"></script>
<SCRIPT>
//work!
requirejs(['/bower_components/jquery/dist/jquery'],()=>{
console.debug($);
})
//error
requirejs(['/bower_components/axios/dist/axios'],()=>{
axios.get('https://httpbin.org/get').then(function(response){
console.log(response.status); // ex.: 200
});
});
</SCRIPT>
</HEAD
The URL is a test service, the error below occurs.
require.js:5 Uncaught Error: Script error for "/bower_components/axios/dist/axios"
https://requirejs.org/docs/errors.html#scripterror
at makeError (require.js:5)
Any URL, or even the below line, the error occurs:
console.debug(axios);
I am using the below version:
"axios": "^0.19.2",
I've checked the AXIOS code and it does support AMD. So you need to use it as a regular AMD:
<HEAD>
<script src="3party/require.js"></script>
<SCRIPT>
requirejs(['/bower_components/jquery/dist/jquery'],()=>{
console.debug($);
})
requirejs(['/bower_components/axios/dist/axios'],(axios)=>{ // axios is given as a argument to a your callback
axios.get('https://httpbin.org/get').then(function(response){
console.log(response.status); // ex.: 200
});
});
</SCRIPT>
</HEAD>
AXIOS will not be available as global but as a local module when you require it :)

How to show the message taken from res.badRequest in Sails client

Recently I have encountered one issue that I want to show the message taken from res.badRequest().
When error happens, my code is like:
var errMsg = 'Begin Date should be before End Date, please check';
sails.log.error(errMsg);
return res.badRequest(errMsg);
but when I tried to get the error message in client, I failed, and here is my code in ejs:
<% if ( res.data ) { %><%=res.data%><% } %>
Where did I make mistake?
Thanks very much in advance.
I use it in Angularjs client and works as documented https://sailsjs.com/documentation/reference/response-res/res-bad-request
myService.sailsController()
.then(function () {
Alert.add({ type: "success", msg: "ok" });
})
.catch(function (err) {
Alert.add({ type: "danger", msg: err.data +" [" + err.statusText + "]"});
});

Require.JS and JS Test Driver: Unexpected token <

I am trying to test a simple Backbone Model loaded via RequireJS:
define ["backbone"], (Backbone)->
class Todo extends Backbone.Model
defaults:
title: ''
priority: 0
done: false
validate: (attrs) ->
errs = {}
hasErrors = false
if (attrs.title is "")
hasErrors = true
errs.title = "Please specify a todo"
if hasErrors
return errs
toggleDone: ->
#save("done", !#get("done"))
return Todo
My tests look like:
requirejs.config
baseUrl: "js/"
paths:
jquery: "https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min"
jqueryui: "https://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min"
json2: "http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2"
underscore: "http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min"
backbone: "http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min"
backboneLocalStorage: "https://raw.github.com/jeromegn/Backbone.localStorage/master/backbone.localStorage-min"
shim:
"underscore":
exports: "_"
"backbone":
deps: ["jquery", "underscore", "json2"]
exports: "Backbone"
"jqueryui":
deps: ["jquery"]
"backboneLocalStorage":
deps: ["backbone"]
exports: "Backbone.LocalStorage"
require ["models/todo"], (Todo) ->
console.log Todo
TodoTests = TestCase("TodoTests")
TodoTests::testCreateTodo = ->
todo = new Todo({ title: "Hello" })
assertEquals "Hello", todo.get("title")
assertEquals 0, todo.get("priority")
assertEquals false, todo.get("done")
The JS Test Driver config:
server: http://localhost:3001
load:
- ../public/js/libs/require.js
- ../public/js/tests.js
serve:
- ../public/js/models/*
- ../public/js/collections/*
- ../public/js/views/*
Problem seen from the JS Test Driver listened page on Chrome console:
Uncaught SyntaxError: Unexpected token <
Looking at Todo.js from Chrome,
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>Console Runner</title><script type="text/javascript">var start = new Date().getTime();</script>
Uncaught SyntaxError: Unexpected token <
<script src="/static/lib/json2.js" type="text/javascript"></script><script src="/static/lib/json_sans_eval.js" type="text/javascript"></script><script src="/static/jstestdrivernamespace.js" type="text/javascript"></script><script src="/static/lib/jquery-min.js" type="text/javascript"></script><script src="/static/runner.js" type="text/javascript"></script><script type="text/javascript">jstestdriver.runConfig = {'debug':false};</script>
<script type="text/javascript">jstestdriver.console = new jstestdriver.Console();
Notice its a HTML page instead of my actual JS. Also console.log(Todo) returns undefined since a HTML page is returned in place of a JS. Did I configure this wrongly?
I struggled with this for days and searched with Google endlessly until I finally found out what JsTestDriver was doing. In your requirejs.config, for your tests to run properly, your baseUrl needs to be:
baseUrl: /test/path/to/your/stuff
The reason is when JsTestDriver makes its server, it prepends /test/ to all the directories. If the baseUrl isn't set properly, it starts trying to send back local a reference to window I think.
The only other problem that I see you may run into is running the tests with the require statement as the first line. I have Jasmine and putting my require() at the top of my tests caused them to never run so I had to do it in my beforeEach for my tests and get the object before they ran.
I'm probably doing something wrong though I see countless other people claiming that the require statement in Jasmine works, so my hunt continues.
Have you checked your ajax responses? I just had the same thing and that '<' was from the opening doctype tag that was returned when the resource 404'd...

Bad request when trying to post to wcf rest 4 service

I am playing with the wcf 4.0 rest template and trying to get it to work with jquery.
I have created a new rest template project and added a webform into the same project just to get things simple.
I have slightly modfied the Create Method to look like this
[WebInvoke(UriTemplate = "", Method = "POST")]
public string Create(SampleItem instance)
{
// TODO: Add the new instance of SampleItem to the collection
return (instance.Id == 1) ? "1 was returned" : "something else was returned";
}
Then from my webform I am using this.
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: 'POST',
url: "/service1/",
data: { "Id": 1,"StringValue": "String content"
},
success: function (data) {
$('.result').html(data);
},
error: function (error) {
$('.result').html(error)
},
dataType: "json",
contentType: "application/json; charset=utf-8"
});
});
</script>
<div class="result"></div>
However fiddler is returning a 400 error telling me there is a request error. Have I done something wrong?
400 can also mean something in your service went wrong. Did you try to attach a debugger to the Rest-service?
Tried to create a .Net-console application (create the request using HttpClient) and communicate with your service?
I ran into same error, after half hour of testing I saw just some error occured in the REST-service.