使用文本数据发送AJAX-Request(JQuery)

时间:2010-11-04 11:27:02

标签: jquery ajax

我想从JQuery发送一些带有$.ajax()方法的数据。问题是,数据(字符串)包括“;”和其他特殊字符。问题是,“;”是键/值的分隔符。我如何通过jquery在POST上提交这个?

以下是代码:

$('#save_patterns').click(function() {
 $('#save_patterns').text('Saving ...')
 var code = $('#article_code').val() // include ";" and stuff
 $.ajax({url: '/extractor/save-patterns',
   type: 'POST', data: code,
   success: function(data) {
    $('#save_patterns').text('Save the patterns')
   }
 })
 return false
})

2 个答案:

答案 0 :(得分:4)

试试这个:

$('#save_patterns').click(function() {
    $('#save_patterns').text('Saving ...')
    var code = $('#article_code').val() // include ";" and stuff
    $.ajax({url: '/extractor/save-patterns',
        type: 'POST', 
        data: { code: code },
        success: function(data) {
            $('#save_patterns').text('Save the patterns')
        }
    })
    return false
})

答案 1 :(得分:0)

('#save_patterns').click(function() {
    $('#save_patterns').text('Saving ...')
    var code = $('#article_code').val() // include ";" and stuff
    $.ajax({ url: '/extractor/save-patterns',
        type: 'POST', 
        data: { code: JSON.stringify(code) },
        success: function(data) {
            $('#save_patterns').text('Save the patterns')
        }
    })
    return false
})

试试这个