我正在POST用一个非常简单的 HTML 提出请求form。请求在form格式上失败,但在 Javascript 中工作。
这很简单,所以这里几乎是整个表单:
<form method="post" action="[apiUrl]" target="_blank">
<input type="hidden" name="payload" value="[payload]">
<!-- ... -->
</form>
Run Code Online (Sandbox Code Playgroud)
*请注意,[apiUrl]和[payload]是注入到 HTML 中的变量。
请求失败并显示来自 API 的自定义消息(似乎无法解析有效负载):
{
"Error": {
"Message": "Noun and Verb are Required Request Parameters",
"ValidationError": false
},
"Result": "ERROR"
}
Run Code Online (Sandbox Code Playgroud)
但是,当由 Javascript 执行时,完全相同的请求会成功(我已经使用 Axios 和 jQuery 以及 Paw 进行了测试)。
$.post(this.apiUrl, this.payload, response => {
console.log('Success!', response);
});
Run Code Online (Sandbox Code Playgroud)
这payload只是一个 Javascript Object。变量设置如下:
this.apiUrl = …Run Code Online (Sandbox Code Playgroud) 我试图将消息附加到对话(多对多),但我收到错误.我错过了什么?
数据透视表模式
conversation_message(conversation_id,message_id)
楷模
class Conversation extends Eloquent
{
public function messages()
{
$this->belongsToMany('Message', 'conversation_message', 'conversation_id', 'message_id');
}
}
class Message extends Eloquent
{
public function conversations()
{
$this->belongsToMany('Conversation', 'conversation_message', 'message_id', 'conversation_id');
}
}
Run Code Online (Sandbox Code Playgroud)
调节器
$conversation = Conversation::find(1);
$message = Message::find(1);
$conversation->messages()->attach($message);
Run Code Online (Sandbox Code Playgroud)
错误
Call to a member function attach() on a non-object
Run Code Online (Sandbox Code Playgroud) 我无法在模拟器或物理手机上获得地理位置.
我正在使用Titanium SDK 1.6.2,ADK 2.2.
我错过了什么?提前致谢.
错误:
e.coords在执行此分配时表示为null.f_lng = e.coords.longitude;
码:
function get_geolocation() {
try {
Ti.Geolocation.preferredProvider = 'gps';
Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
Titanium.Geolocation.distanceFilter = 10;
if( Titanium.Geolocation.locationServicesEnabled === false ) {
throw('Your device has GPS turned off. Please turn it on.');
}
var f_lat, f_lng;
Titanium.Geolocation.getCurrentPosition(function(e) {
if( ! e.success || e.error ) {
alert("Unable to get your location.");
}
f_lng = e.coords.longitude;
f_lat = e.coords.latitude;
});
return {
's_status': 'success', …Run Code Online (Sandbox Code Playgroud) 有可能将remember(60)功能应用于类似的东西Service::all()吗?
这是一个很少会改变的数据集.我尝试了几种变化但没有成功:
Service::all()->remember(60);Service::all()->remember(60)->get();(Service::all())->remember(60);当然,我知道其他可用的缓存方法,但我更喜欢这种方法的清洁度(如果有的话).
我试图discount_code从对象内引用属性,但我不断收到以下错误.我怎样才能访问discount_code?
错误:
未捕获的TypeError:无法调用未定义的方法'val'
HTML:
<input type="text" name="txt_discount_code" value="12345" />
Run Code Online (Sandbox Code Playgroud)
JS:
var cart = {
transaction: {},
discount_code: $('input[name=txt_discount_code]'),
get_cart_items_params: {
page: 'checkout',
s_method: 'get-cart-items',
txt_discount_code: this.discount_code.val()
// txt_discount_code: cart.discount_code.val()
}
};
Run Code Online (Sandbox Code Playgroud) 如何在 Ajax 调用中访问响应数据?如果我登录,response.text()它会显示一个PromiseObj.
安慰
PromiseObj
context: undefined
promise: Promise {status: "resolved", result: ")]}',?{\"Result\":\"SUCCESS\",\"Data\":{\"mode\":\"DEV\"}}"}
Run Code Online (Sandbox Code Playgroud)
代码
this.$http.post(endpoint, data, []).then((response) => {
console.log(response.status);
console.log(response.text());
}, (response) => {
console.log(response.status);
console.log(response.json());
});
Run Code Online (Sandbox Code Playgroud) javascript ×3
jquery ×2
laravel-4 ×2
php ×2
android ×1
caching ×1
eloquent ×1
forms ×1
geolocation ×1
html ×1
promise ×1
titanium ×1
vue-resource ×1
vue.js ×1