如何通过在$ ajax的POST参数? [英] How to pass parameters in $ajax POST?

查看:133
本文介绍了如何通过在$ ajax的POST参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也跟着教程在的链接说明。在下面由于某些原因,code中的数据不附加到URL的参数,但如果我直接使用它们设置的URL /?字段1 =你好它的工作原理。

  $。阿贾克斯({
        网址:'超人',
        键入:POST,
        数据:{字段1:你好,FIELD2:hello2},
        的contentType:应用/ JSON的;字符集= UTF-8,
        成功:函数(响应){
            警报(response.status);
        },
        错误:函数(){
            警报(错误);
        }
    });
 

解决方案

如果您不需要使用故障的功能,我建议你利用的 $。交 或的 $。获得 的jQuery的语法。

  $后期('超人',{字段1:你好,FIELD2:hello2},
    功能(returnedData){
         执行console.log(returnedData);
});
 

I have followed the tutorial as stated in this link. In the code below for some reason the data is not appended to the url as parameters, but if I set them directly to the url using /?field1="hello" it works.

$.ajax({
        url: 'superman',
        type: 'POST',
        data: { field1: "hello", field2 : "hello2"} ,
        contentType: 'application/json; charset=utf-8',
        success: function (response) {
            alert(response.status);
        },
        error: function () {
            alert("error");
        }
    }); 

解决方案

If you don't need to make use of the failure function, I would recommend you to make use of the $.post or $.get syntax of jQuery.

$.post('superman', { field1: "hello", field2 : "hello2"}, 
    function(returnedData){
         console.log(returnedData);
});

这篇关于如何通过在$ ajax的POST参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆